strsplit

Splits a string by delimiters. (version 4.67 or later)

Format

strsplit <strval> <separator> [<count>]

Remarks

Splits the string <strval> by the <separator> delimiter, and returns the 9 system variables from "groupmatchstr1" to "groupmatchstr9".

One delimiter character is specified in the <separator>.

The <count> is specified the maximum number of substrings to return. The upper limit of <count> is 9.
If a number of substrings is smaller than <count>, the remaining groupmatchstr variables stores ''(empty).
When the number of substrings are greater than the <count>, the remaining substrings stores into the last groupmatchstr variable.

When the <count> is not specified, the maximum of substrings is 9.
If the number of substrings is larger than 9, the ninth substring stores into the last groupmatchstr variable.

The division count stores into the system variable "result".
When the <count> is not specified and the number of substrings is larger than 9, the "result" is set to 10.

Example

src=',,Sun,Mon,Tue,,Thu,Fri,Sat'
strsplit src ',' 7

messagebox groupmatchstr1 "groupmatchstr1" ; ''
messagebox groupmatchstr2 "groupmatchstr2" ; ''
messagebox groupmatchstr3 "groupmatchstr3" ; 'Sun'
messagebox groupmatchstr4 "groupmatchstr4" ; 'Mon'
messagebox groupmatchstr5 "groupmatchstr5" ; 'Tue'
messagebox groupmatchstr6 "groupmatchstr6" ; ''
messagebox groupmatchstr7 "groupmatchstr7" ; 'Thu,Fri,Sat'
messagebox groupmatchstr8 "groupmatchstr8" ; ''
messagebox groupmatchstr9 "groupmatchstr9" ; ''
messagebox result         "result"         ; 7

src='Sun,Mon,Tue,Wed,Thu,Fri,Sat'
strsplit src ',' 7

messagebox groupmatchstr1 "groupmatchstr1" ; 'Sun'
messagebox groupmatchstr2 "groupmatchstr2" ; 'Mon'
messagebox groupmatchstr3 "groupmatchstr3" ; 'Tue'
messagebox groupmatchstr4 "groupmatchstr4" ; 'Wed'
messagebox groupmatchstr5 "groupmatchstr5" ; 'Thu'
messagebox groupmatchstr6 "groupmatchstr6" ; 'Fri'
messagebox groupmatchstr7 "groupmatchstr7" ; 'Sat'
messagebox groupmatchstr8 "groupmatchstr8" ; ''
messagebox groupmatchstr9 "groupmatchstr9" ; ''
messagebox result         "result"         ; 7

src='A string'#10'of ,,tokens'#10'and some  more tokens'
strsplit src '\n' 9

messagebox groupmatchstr1 "groupmatchstr1" ; 'A string'
messagebox groupmatchstr2 "groupmatchstr2" ; 'of ,,tokens'
messagebox groupmatchstr3 "groupmatchstr3" ; 'and some  more tokens'
messagebox groupmatchstr4 "groupmatchstr4" ; ''
messagebox groupmatchstr5 "groupmatchstr5" ; ''
messagebox groupmatchstr6 "groupmatchstr6" ; ''
messagebox groupmatchstr7 "groupmatchstr7" ; ''
messagebox groupmatchstr8 "groupmatchstr8" ; ''
messagebox groupmatchstr9 "groupmatchstr9" ; ''
messagebox result         "result"         ; 3

src='1,2,3,4,5,6,7,8,9,0'
strsplit src ','

messagebox groupmatchstr1 "groupmatchstr1" ; '1'
messagebox groupmatchstr2 "groupmatchstr2" ; '2'
messagebox groupmatchstr3 "groupmatchstr3" ; '3'
messagebox groupmatchstr4 "groupmatchstr4" ; '4'
messagebox groupmatchstr5 "groupmatchstr5" ; '5'
messagebox groupmatchstr6 "groupmatchstr6" ; '6'
messagebox groupmatchstr7 "groupmatchstr7" ; '7'
messagebox groupmatchstr8 "groupmatchstr8" ; '8'
messagebox groupmatchstr9 "groupmatchstr9" ; '9'
messagebox result         "result"         ; 10

See also