PDA

View Full Version : Usage of the SPLIT Keyword



Michael Clease
28-05-2007, 14:35
' Usage of the SPLIT Keyword example
'
' Return Number the number of tokens found.

'
' Written by Abraxas

DIM sMainString AS STRING VALUE "THIS,IS,MY,STRING" '
DIM ArrayName() AS DWORD value 0
DIM Delimiter AS STRING VALUE "," ' Character used to seperate
dim n as DWORD Value 0
DIm sMsg AS STRING

sMsg = "SMainString = " & sMainString & $CRLF & $CRLF
sMsg += "Delimiter = " & Delimiter & $CRLF & $CRLF
sMsg += "Tokens found = " & SPLIT(sMainString, Delimiter, ArrayName)

MSGBOX 0, sMsg

ErosOlmi
28-05-2007, 14:46
Modified to:



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

sMsg = "SMainString = " & sMainString & $CRLF & $CRLF
sMsg += "Delimiter = " & Delimiter & $CRLF & $CRLF
nTokens = SPLIT(sMainString, Delimiter, ArrayName)
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

Michael Clease
28-05-2007, 23:39
just to make it easier to read. What do you think?



nTokens = SPLIT(sMainString, Delimiter, ArrayName)

sMsg = "SMainString = " & sMainString & $CRLF & $CRLF
sMsg += "Delimiter = " & Delimiter & $CRLF & $CRLF
sMsg += "Tokens found = " & nTokens & $CRLF & $CRLF

ErosOlmi
29-05-2007, 03:26
Agree. Thanks