Function Reference

StringSplit

Splits up a string into substrings depending on the given delimiters.

StringSplit ( "string", "delimiters" [, flag ] )

 

Parameters

string The string to evaluate.
delimiters One or more characters to use as delimiters.
flag [optional] If flag is 0 (the default), then each character in the string will mark where to split the string. If flag is 1, then the entire delimiter string is needed to mark the split.

 

Return Value

Returns an array, the first element ($array[0]) contains the number of strings returned, the remaining elements ($array[1], $array[2], etc.) contain the delimited strings.
If no delimiters were found @error is set to 1, the count is 1 ($array[0]) and the full string is returned ($array[1]).

 

Remarks

If you use a blank string "" for the delimiters, each character will be returned as an element.

If the delimiter you wish to use is a substring instead of individual single characters, see the second example below.

StringSplit is very useful as an alternative to StringInStr and as a means to populate an array.

 

Related

String, StringInStr, StringLeft, StringLen, StringLower, StringMid, StringReplace, StringRight, StringTrimLeft, StringTrimRight, StringUpper

 

Example


$days = StringSplit("Sun,Mon,Tue,Wed,Thu,Fri,Sat", ",")
;$days[1] contains "Sun" ... $days[7] contains "Sat"

$text = "This\nline\ncontains\nC-style breaks."
$array = StringSplit(StringReplace($text, "\n", @LF), @LF)