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

Dig Deeper on Domino Resources - Part 4



  • Favorite iSeries cheat sheets

    Here you'll find a collection of valuable cheat sheets gathered from across the iSeries/ community. These cheat ...

  • HTML cheat sheet

    This is a really cool cheat sheet if you're looking to learn more about HTML. You'll find just about everything you every wanted ...

  • Carol Woodbury: Security

    Carol Woodbury