Manage Learn to apply best practices and optimize your operations.

Split String

The sub Click is the example call, tokStrInArray and strTok$ are the
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

' 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
' 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
strTok$ = Mid$(SaveStr$, BegPos%, EndPos% - BegPos%)
' Set starting point for search for next token.
start% = EndPos%

End Function
This was last published in November 2000

Dig Deeper on Domino Resources - Part 4

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.




  • iSeries tutorials's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

  • V6R1 upgrade planning checklist

    When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

  • Connecting multiple iSeries systems through DDM

    Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...