WebSiphon 2 Guide: String Functions
contents prev next

binaryToString
chr
find
listToString
lowercase
ord
replace
split
stringToBinary
stringToList
strlen
substring
uppercase
binaryToString ( binary-data [, start, length ])
Returns: string Location: MiscLib
ParameterDescription
binary-dataany binary data
[start]starting character position [optional]
[length]length of the resulting substring [optional]

Returns a string representing the value of binary-data. If binary-data contains any non-ASCII characters, the resulting string will not be a readable string but will contain garbage. The returned string will begin with the character position start and continue until either the end of the data or length characters total.

Example:

// Sets my_string to the first 5 characters of "hello.data"
binary_data = readBinaryFile("Macintosh HD:Desktop Folder:hello.data");
my_string = binaryToString(binary_data, 1, 5);
chr ( integer )
Returns: string Location: Built-in
ParameterDescription
stringinteger

This function, when passed an ASCII code, returns the associated character.

Example:

print chr(65);
>> A 

See Also:

find ( string, string-to-find [, start ])
Returns: integer Location: Built-in
ParameterDescription
stringany string
string-to-findthe string to match
[start]character position to start at in string [optional]

This function will return the first occurrence of string-to-find in string, starting with either the first character, or start, if it is defined. If string-to-find is not present, the value 0 will be returned.

Using the start parameter, finding all occurences of one string within another can be done with a loop such as the one in the example below.

Example:

search_string = "whoop there it is! whoop whoop!";
find_string = "whoop";
start = 1;
match_list = [];
repeat until (start = 0)
  this_one = find(search_string, find_string, start);
  if (this_one != 0) then
    match_list = match_list & this_one;
    start = this_one + 1;
  else
    start = this_one;
  end if;
end repeat;
print match_list;

>> 1 20 26
listToString ( list )
Returns: string Location: StringUtils.lib
ParameterDescription
listany list

Returns a string comprised of all items in the list specified in list.

Example:

my_list = ["a" "b" "c" "d" "e"];
print listToString(my_list);

>> abcde

See Also:

lowercase ( string )
Returns: string Location: Built-in
ParameterDescription
stringany string

Returns a copy of string, with all uppercase characters converted to their lowercase equivalents. Any non-alpha characters in string are left unchanged.

Example:

print lowercase( "PUSH SOME KEYS, pleasE!");
>> push some keys, please!

See Also:

ord ( string )
Returns: integer Location: Built-in
ParameterDescription
stringany character

This function, when passed a single character in a string, returns the associated ASCII code. Passing a string will only convert the first character.

Example:

print ord("A");
>> 65 

See Also:

replace ( string, match, replacement )
Returns: string Location: Built-in
ParameterDescription
stringany string
matchstring pattern to match
replacementreplacement string

This function replaces all occurences of match in string with the replacement string specified by replacement.

Example:

str = "There comes a time when...";
print replace( str, " ", "*");

>> There*comes*a*time*when...
split ( string, delimiter )
Returns: list Location: Built-in
ParameterDescription
stringany string
delimitera delimiter used to separate string

This powerful function can be used in many different cases. It requires two parameters, string and delimiter. A list is returned that contains each portion of the first string, split by the specified delimiter.

For example, this can be used to coerce comma separated numbers into a list of usable numbers as shown below.

Example:

the_string = "1, 2, 3, 4, 5";
the_list = split(the_string, ", ");
printList(the_list);

>> ["1" "2" "3" "4" "5"]
stringToBinary ( string )
Returns: binary Location: MiscLib
ParameterDescription
stringany string

This function will take any text string passed using string and convert it into a binary value that can be used with the file and resource functions, such as those listed below.

See Also:

stringToList ( string )
Returns: list Location: StringUtils.lib
ParameterDescription
stringany string

This function will take any text string passed using string and convert it into a list where each item is a single character from the string. This is helpful when performing single character operations on a string allowing you to use the list item accessors. To convert back to a string use the listToString() function.

Example:

my_string = stringToList("image_a.gif");
my_string'7 = "b";
print listToString(my_string);

>> image_b.gif

See Also:

strlen ( string )
Returns: integer Location: Built-in
ParameterDescription
stringany string

Returns the total number of characters in string. Any type other than a string will be coerced to a string prior to counting characters.

Example:

  1. my_string = "Hello world.";
    print strlen(my_string);
    
    >> 12
  2. some_num = 14;
    print strlen(some_num);
    
    >> 2
substring ( string, start [, length ])
Returns: string Location: Built-in
ParameterDescription
stringany string
startstarting character position
[length]length of the resulting substring [optional]

Returns a subsection of string, starting with character position start, and continuing until either the end of the string or length characters total.

Examples:

  1. my_string = "The quick brown fox...";
    print substring(my_string, 5, 5);
    
    >> quick
  2. silly_string = "Praise the glorious parsnip!";
    print substring(silly_string, 12);
    
    >> glorious parsnip!
uppercase ( string )
Returns: string Location: Built-in
ParameterDescription
stringany string

Returns a copy of string, with all lowercase characters converted to their uppercase equivalents. Any non-alpha characters in string are left unchanged.

Example:

print uppercase("Whoop! Whoop!");

>> WHOOP! WHOOP!

See Also:

contents prev next

Copyright (c)1996-2003 Purity Software