parseString
parseString(S_string[S_breakCharacters] [g_insertEmptyString] ) =>l_strings
Description
Breaks a string into a list of substrings with break characters.
Returns the contents of S_string broken up into a list of words. If the optional second argument, S_breakCharacters, is not specified, the white space characters, \t\f\r\n\v, are used as the default. If the third optional argument g_insertEmptyString is provided, an empty string is inserted under the following three conditions:
-
when
S_breakCharactersis the first letter in the string. -
when
S_breakCharactersis the last letter in the string. -
when
S_breakCharactersis after anotherS_breakCharacters.
A sequence of break characters in S_string is treated as a single break character. By this rule, two spaces or even a tab followed by a space is the same as a single space. If this rule were not imposed, successive break characters would cause null strings to be inserted into the output list.
If S_breakCharacters is a null string, S_string is broken up into characters. You can think of this as inserting a null break character after each character in S_string.
No special significance is given to punctuation characters, so the “words” returned by parseString might not be grammatically correct.
Arguments
|
Generates the list of strings to include empty string when set to |
Value Returned
Examples
Space is the default break character.
parseString( "Now is the time" )
=> ("Now" "is" "the" "time")
parseString( "prepend" "e" )
=> ("pr" "p" "nd" )
A sequence of break characters in S_string is treated as a single break character.
parseString( "feed" "e")
=> ("f" "d")
Both . and / are break characters.
parseString( "~/exp/test.il" "./")
=> ("~" "exp" "test" "il")
The single space between c and d contributes " " in the return result.
parseString( "abc de" "")
=> ("a" "b" "c" " " "d" "e")
Splits the string at each occurrence of the delimiter character "-".
parseString( "-abc-def--ghi-" "-" )
=> ("abc" "def" "ghi")
Inserts an empty string at each occurrence of the delimiter character "-".
parseString( "-abc-def--ghi-" "-" t )
=> ("" "abc" "def" "" "ghi" "")
parseString "-abc"
=> ("" "abc")
parseString "abc-"
=> ("abc" "")
parseString "abc--xyz"
=> ("abc" "" "xyz")
The above result can be used with buildString() to reconstruct the original string or replacing the delimiter character.
buildString( parseString( string delimiter t) delimiter)
Related Topics
Return to top