Chapter 19. A collection of standard string functions
Functions to get the length, a substring, getting at individual characters, string seaching, escaping, tokenizing, and converting strings to longs.
Name
function::strlen — Returns the length of a string.
Synopsis
function strlen:long(s:string)
General Syntax
strlen: long (str:string)
Description
This function returns the length of the string, which can be zero up to MAXSTRINGLEN.
Name
function::substr — Returns a substring.
Synopsis
function substr:string(str:string,start:long,length:long)
Arguments
str
The string to take a substring from
start
Starting position. 0 = start of the string.
length
Length of string to return.
General Syntax
substr:string (str:string, start:long, stop:long)
Description
Returns the substring of the up to the given length starting at the given start position and ending at given stop position.
Name
function::stringat — Returns the char at a given position in the string.
Synopsis
function stringat:long(str:string,pos:long)
Arguments
str
The string to fetch the character from.
pos
The position to get the character from. 0 = start of the string.
General Syntax
stringat:long(srt:string, pos:long)
Description
This function returns the character at a given position in the string or zero if thestring doesn't have as many characters.
Name
function::isinstr — Returns whether a string is a substring of another string.
Synopsis
function isinstr:long(s1:string,s2:string)
Arguments
s1
String to search in.
s2
Substring to find.
General syntax
isinstr:long (s1:string, s2:string)
Description
This function returns 1 if string s1 contains s2, otherwise zero.
Name
function::text_str — Escape any non-printable chars in a string.
Synopsis
function text_str:string(input:string)
Arguments
input
The string to escape.
General Syntax
text_str:string (input:string)
Description
This function accepts a string argument, and any ASCII characters that are not printable are replaced by the corresponding escape sequence in the returned string.
Name
function::text_strn — Escape any non-printable chars in a string.
Synopsis
function text_strn:string(input:string,len:long,quoted:long)
Arguments
input
The string to escape.
len
Maximum length of string to return. 0 means MAXSTRINGLEN.
quoted
Put double quotes around the string. If input string is truncated it will have “...” after the second quote.
General Syntax
text_strn:string (input:string, len:long, quoted:long)
Description
This function accepts a string of designated length, and any ASCII characters that are not printable are replaced by the corresponding escape sequence in the returned string.
Name
function::tokenize — Return the next non-empty token in a string.
Synopsis
function tokenize:string(input:string,delim:string)
Arguments
input
String to tokenize. If NULL, returns the next non-empty token in the string passed in the previous call to tokenize
.
delim
Token delimiter. Set of characters that delimit the tokens.
General Syntax
tokenize:string (input:string, delim:string)
Description
This function returns the next non-empty token in the given input string, where the tokens are delimited by characters in the delim string. If the input string is non-NULL, it returns the first token. If the input string is NULL, it returns the next token in the string passed in the previous call to tokenize. If no delimiter is found, the entire remaining input string is returned. It returns NULL when no more tokens are available.
Name
function::str_replace — str_replace Replaces all instances of a substring with another.
Synopsis
function str_replace:string(prnt_str:string,srch_str:string,rplc_str:string)
Arguments
prnt_str
The string to search and replace in.
srch_str
The substring which is used to search in prnt_str string.
rplc_str
The substring which is used to replace srch_str.
General Syntax
str_replace:string(prnt_str:string, srch_str:string, rplc_str:string)
Description
This function returns the given string with substrings replaced.
Name
function::strtol — strtol - Convert a string to a long.
Synopsis
function strtol:long(str:string,base:long)
Arguments
str
String to convert.
base
The base to use
General Syntax
strtol:long (str:string, base:long)
Description
This function converts the string representation of a number to an integer. The base parameter indicates the number base to assume for the string (eg. 16 for hex, 8 for octal, 2 for binary).
Name
function::isdigit — Checks for a digit.
Synopsis
function isdigit:long(str:string)
General Syntax
isdigit:long(str:string)
Description
Checks for a digit (0 through 9) as the first character of a string. Returns non-zero if true, and a zero if false.