
Parsing strings as tokens
set tokens = createobject("scripting.dictionary")
strTokens = "alpha: a, bravo: b, charlie: c, delta: d, echo: e"
arTokens = split(strTokens,",")
for each item in arTokens
temp = split(item,":")
tokens(trim(temp(0))) = trim(temp(1))
next
s = ""
for each k in tokens.keys
s = s & "token " & k _
& " is equal to " & tokens(k) & vbcrlf
next
msgbox s
--
Michael Harris
Microsoft.MVP.Scripting
--
Please do not email questions - post them to the newsgroup instead.
--
Is there VBScript example code on the net that allows one to parse chunks of text
as tokens? For example, if I had a formatted string like:
alpha: a, bravo: b, charlie: c, delta: d, echo: e, ...
I would like to be able to search for the token "alpha:" and then pick the next
token (which happens to be "a") then search for the token "bravo:" and pick the
next token (which happens to be "b"), etc.
Java has a "tokenizer" class that makes this kind of text work easy. There is no
similar class in VBScript, but someone may have written one.
Dave