Functions for Strings
CountStringTokens function
Counts how many string-separated tokens a string contains.
Synopsis
%tokens = CountStringTokens("one;two;three;four", ";") // sets %tokens to 4
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string which contains tokens |
| string | yes | A string which separates tokens in |
Returns
If
stringis an empty string, returns 0.Otherwise, returns the number of occurrences of
separatorinstring, plus 1.
FormatString_inplace function
Synopsis
%result = 42
%message = FormatString_inplace("The result is %result")
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | String with embedded references to variables |
Returns
The function returns a string in which all references to local and global variables are replaced by the respective stored values.
GetStringToken function
Returns one token from a token string.
Synopsis
%sub_token = GetStringToken("one;two;three;four", ";", 1) // sets %sub_token to "two"
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string which contains tokens |
| string | yes | A string which separates tokens in |
| number | yes | Index of the token within |
Returns
If
indexis a number equal to or greater than zero and less than the value returned byCountStringTokens, returns the portion of string between the (index-1)-th andindex-th occurrence ofseparator.For
indexequal to 0, this is the portion ofstringbefore the firstseparator.For
indexequal to the result ofCountStringTokens, this is the portion ofstringafter the lastseparator.
Otherwise, returns an empty string.
regex_match function
Matches a string against a regular expression.
Synopsis
%res = regex_match("Hello world", "[he]+ll..w.*", icase) // result: 1
%res = regex_match("Hello world", "ll..w", icase) // result: 0
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string to examine. |
| string | yes | The regular expression. |
| string | no | Makes the match case insensitive. |
Returns
1 if string matches regex, and 0 otherwise.
Remarks
The match is case insensitive if the
icaseparameter is present and has the value "icase" in any combination of upper and lower case characters.The regular expression uses ECMAScript syntax.
regex_search function
Searches within a string for a substring that matches the regular expression.
Synopsis
%res = regex_search("Hello world", "LL..w") // result: 0
%res = regex_search("Hello world", "LL..w", icase) // result: 1
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string to examine. |
| string | yes | The regular expression. |
| string | no | Makes the match case insensitive. |
Returns
1 if string contains a portion that matches regex, and 0 otherwise.
Remarks
The match is case insensitive if the
icaseparameter is present and has the value "icase" in any combination of upper and lower case characters.The regular expression uses ECMAScript syntax.
replacechr function
Replaces all occurrences of a character in a string by another character.
Synopsis
%result = replacechr("Hello world", "o", "x") // result: "Hellx wxrld"
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string to work on. |
| string | yes | The character to be replaced. |
| string | yes | The replacement character. |
Returns
The string string, with all occurrences of search replaced by replace.
Remarks
If either
searchorreplace(or both) are empty strings,replacechrreturns string.If
searchorreplaceare more than 1 character long, only the first character is used.
strcat function
Concatenates several strings into one.
Synopsis
%message = strcat("We have ", %number_of_hens, " and they have laid ", %number_of_eggs, ", of which ", %number_of_broken, " were broken.")
Parameters
strcat takes from one to any number of parameters. Numeric values are implicitly converted into strings.
Returns
The function returns a string which is created from the concatenation of the values from all parameters.
strchr, strrchr functions
Finds the first or last occurrence of a character within a string.
Synopsis
%first_pos = strchr("Hello world", "o") // returns 4
%last_pos = strrchr("Hello world", "o") // returns 7
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string |
| string | yes | The character to find (only the first character of this parameter is used) |
Returns
The 0-based offset of the position of the first (for strchr) or last (strrchr) occurrence of the first character of char within str.
strcmp function
Compares two strings for equality.
Synopsis
if (strcmp(%data, "OK", icase))
{
return
}
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The first string |
| string | yes | The second string |
| string | no | If set to |
Returns
If
string1andstring2are identical with respect to length and content, returns 1.If
ignore_caseis present and contains the value"icase", andstring1andstring2are identical with respect to length and content, except for upper and lower case, return 1.Otherwise returns 0.
strlen function
Counts the characters in a string.
Synopsis
%str = "This is my string."
%len = strlen(%str)
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string whose length is to be calculated |
Returns
The number of characters in string. (If stringis a number, it is converted into a string before the length is calculated.)
strsearch function
Returns a value that indicates whether a string contains a certain sub string.
Synopsis
%contains = strsearch("YesNo", %answer, icase)
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string which is to be scanned for |
| string | yes | The sub string that should be detected in |
| string | no | If set to |
Returns
If
search_stringis an empty string, returns 1.Otherwise, if
search_stringis exactly contained in string, returns 1.Otherwise, if
ignore_caseis specified as"icase", andsearch_stringis contained instringif upper/lower case is not regarded, returns 1.Otherwise, returns 0.
strstr function
Returns the offset of a sub string within a string.
Synopsis
%position = strstr("YesNo", %answer, icase)
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string which is to be scanned for |
| string | yes | The sub string that should be detected in |
| string | no | If set to |
Returns
If
search_stringis an empty string, returns 0.Otherwise, if
ignore_caseis specified as"icase", andsearch_stringis contained instringif upper/lower case is not regarded, returns the offset of the first occurrence of search_string from the start of string.Otherwise, if
search_stringis exactly contained instring, returns the offset of the first occurrence of search_string from the start of string.Otherwise, returns -1.
strupper function
Converts a string into all upper case.
Synopsis
%upper = strupper("Hello world!") // result: "HELLO WORLD!"
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string |
Returns
The string str, converted to upper case.
substr function
Returns a part of a string.
Synopsis
%sub = substr("Hello world", 4, 3) // assigns "o w" to %sub
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| string | yes | The string from which a part is to be extracted. |
| number | yes | Index of the first character to extract from the beginning of |
| number | no | Number of characters to extract. If not specified, takes everything up to the end of |
Returns
If
startis negative or equal to or greater than the length ofstring, returns an empty string.Otherwise, if
lengthis not supplied or is zero or negative, returns the part ofstringthat starts atoffsetand extends to the end of thestring.Otherwise returns the part of
stringthat starts atoffsetstart and extends to the end of the string, but at mostlengthcharacters.
string function
Converts a value into a string.
Synopsis
%str = string(%my_value)
Parameters
Name | Type | Required? | Description |
|---|---|---|---|
| any | yes | The value that is to be converted |
Returns
If
valueis a string returnsvalue.Otherwise, converts
valueinto a string and returns it as string.