STRING.split
Splits the current string around matches of the given regular expression.
Syntax
split(
regex STRING )
RETURNS DYNAMIC ARRAY OF STRING
- regex is the regular expression defining token separators. See Regular expression patterns.
Usage
This method scans the current string value and generates a dynamic array with all tokens terminated by separators matching the regular expression passed as parameter.
The tokens can be terminated by the substring that matches the regular expression, or is terminated by the end of the string.
If the expression does not match any part of the input, then the resulting array has just one element, which is a copy of this string.
`\b` instead of "\\b" or
'\\b' )If the regular expression is NULL, it matches an empty separator at every
position, splitting the source string into its individual characters. The resulting array then
contains one element per character, preceded and followed by an additional empty string element. For
example, the source string "abc" will be splitted into array elements [ "",
"a", "b", "c", "" ] .
Splitting with an NULL regular expression follows the runtime character set.
With a multibyte character set such as UTF-8, the string is split into characters and multibyte
characters are kept together; with a single-byte character set, the string is split into individual
bytes. This behavior depends on the runtime locale
(LC_ALL/LANG), not on the FGL_LENGTH_SEMANTICS setting.
Example
MAIN
DEFINE s STRING
DEFINE tokens DYNAMIC ARRAY OF STRING
DEFINE x INTEGER
LET s = "aa bb;cc:dd"
LET tokens = s.split(`[ ;:]`)
FOR x=1 TO tokens.getLength()
DISPLAY tokens[x]
END FOR
END MAIN
aa
bb
cc
dd