Navigation: thinBasic Modules > Core > String handling > SPLIT |
|
Description
Dimension and fill an array with tokens taken from a string.
Returns the number of tokens found. Tokens are detected using a token delimiter.
Syntax
n = SPLIT(MainString, Delimiter, ArrayName)
Returns
Number, the number of tokens found.
Parameters
Name |
Type |
Optional |
Meaning |
MainString |
String |
No |
The string to split |
Delimiter |
String |
No |
Delimiter to use to separate each of the elements in the array. |
ArrayName |
Array |
Yes |
An array variable. |
Remarks
MainString is first trimmed for spaces or tabs.
If MainString starts or ends with Delimiter char, they will be removed.
ArrayName must exists but dimensioning is automatic.
If ArrayName is a numeric array elements will be automatically converted into numbers
Restrictions
See also
Examples
Thanks to Abraxas for the following script example
' Usage of the SPLIT Keyword example
'
' Return Number the number of tokens found.
Dim sMainString As String VALUE "THIS,IS,MY,STRING" '
Dim ArrayName() As String
Dim Delimiter As String VALUE "," ' Character used to seperate
Dim nTokens As DWORD
Dim Counter As DWORD
Dim sMsg As String
nTokens = SPLIT(sMainString, Delimiter, ArrayName)
sMsg = "SMainString: " & sMainString & $CRLF & $CRLF
sMsg += "Delimiter: " & Delimiter & $CRLF & $CRLF
sMsg += "Tokens found: " & nTokens & $CRLF & $CRLF
sMsg += "Tokens are the following:" & $CRLF
For Counter = 1 To nTokens
sMsg += format$(Counter, "000") & $Tab & ArrayName(Counter) & $CRLF
Next
MSGBOX 0, sMsg
© 2004-2008 thinBasic. All rights reserved. | Version 1.7.0.0 | Web Site: http://www.thinbasic.com |