Name
SplitStr -- split a string in several pieces (V2.0)
Synopsis
table, count = SplitStr(src$, token$[, multiple])
Function
This function splits the string specified in src$ into several pieces by looking for the separator token$ in src$. token$ must be a string containing at least one character that shall act as a separator in src$. SplitStr() will return a table containing all the pieces and the number of pieces in the string as the second return value.

If the specified token does not appear in the source string, src$ is returned.

Starting with Hollywood 7.1 there is a new optional argument named multiple. If this is set to True, multiple occurrences of token$ next to each other will be considered a single occurrence. This can be useful when using the space character as token$ and you want this function to work with an arbitrary number of spaces between the different parts.

Note that before Hollywood 8.0, token$ was limited to a string using only one character. This limit has been lifted for Hollywood 8.0 and the string can now be of arbitrary length.

Inputs
src$
string to split
token$
one character string containing a separator token
multiple
optional: whether or not to treat multiple occurrences of token$ next to each other as a single token (defaults to False) (V7.1)
Results
table
table where the new substrings are stored
count
how many substrings this function created
Example
array, c = SplitStr("AmigaOS3|MorphOS|AmigaOS4|WarpOS|AROS", "|")
For k = 1 To c Do NPrint(array[k - 1])
The above code will print
 
AmigaOS3
MorphOS
AmigaOS4
WarpOS
AROS

The variable c will be set to 5 because SplitStr() finds five substrings and places them in the table specified.


Show TOC