SPLIT

<< Click to Display Table of Contents >>

Navigation:  ThinBASIC Core Language > BuiltIn Functions > String functions >

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.

If Delimiter will be null, all single characters of MainString will be splitted. See Remarks

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

 

If Delimiter is a null string, every character of MainString will be considered to be splitted into target array. In this case return value will be equal to the length of MainString and ArrayName will be dimensioned as well to the number of chars found.

If MainString length will be null, 1 will be returned and ArrayName will be dimensioned to one empty string.

 

Restrictions

 

See also

 

JOIN$,

 

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