Split String
implementation.
Sub Click(Source As Button)
Dim ArrayList$(), i
tokStrInArray ArrayList$(), "One;Two;Three", ";"
For i = Lbound(ArrayList$) To Ubound(ArrayList$)
Msgbox ArrayList$(i)
Next i
End Sub
Sub tokStrInArray (Array$(), st$, Delimiters$)
Dim i As Integer, j As Integer, Token$
ReDim tmp$(640) ' temporary array
' Invoke StrTok$ with the string to tokenize.
Token$ = strTok$(st$, Delimiters$)
i = 0
Do While Token$ <> ""
' Transfer to temporary array
i = i + 1
tmp$(i) = Token$
' Call StrTok$ with a null string so it knows this
' isn't the first call.
Token$ = strTok$("", Delimiters$)
If i >= 640 Then Exit Do
Loop
' Redimension CLArgs$() and transfer values from tmp$()
ReDim Array$(1 To i)
For j = 1 To i
Array$(j) = tmp$(j)
Next j
End Sub
Function strTok$ (Srce$, Delim$)
Dim BegPos%, EndPos%, Ln%
Static start%, SaveStr$
' If first call, make a copy of the string.
If Srce$ <> "" Then
start% = 1: SaveStr$ = Srce$
End If
BegPos% = start%: Ln% = Len(SaveStr$)
' Look for start of a token (character that isn't delimiter).
While BegPos% <= Ln% And InStr(Delim$, Mid$(SaveStr$, BegPos%, 1)) <> 0
BegPos% = BegPos% + 1
Wend
' Test for token start found.
If BegPos% > Ln% Then
strTok$ = "": Exit Function
End If
' Find the end of the token.
EndPos% = BegPos%
While EndPos% <= Ln% And InStr(Delim$, Mid$(SaveStr$, EndPos%, 1)) = 0
EndPos% = EndPos% + 1
Wend
strTok$ = Mid$(SaveStr$, BegPos%, EndPos% - BegPos%)
' Set starting point for search for next token.
start% = EndPos%
End Function