Parsing strings as tokens 
Author Message
 Parsing strings as tokens

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



Tue, 22 Jul 2003 06:00:45 GMT  
 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



Tue, 22 Jul 2003 08:28:47 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Parse search string into query string?

2. Parsing a string for integer

3. Please help: parsing a string.

4. parsing delimited strings

5. Function to parse a string

6. string parsing

7. Parsing a query string

8. Parsing and Deparsing a string

9. Parsing a string

10. String parsing help

11. Newbie Ques, How to Parse String and Display

12. Parsing a string and creating an array

 

 
Powered by phpBB® Forum Software