Archive: Parsing a string?


Parsing a string?
I would like to parse a string in a loop until all the tokens have been processed.

I'm looking at StrTok from StrFunc.nsh, and it looks promising, but I don't see a way to detect when all of the tokens have been retrieved.

StrTok returns an empty string once all the tokens have been retrieved, but it can also return an empty string for empty tokens (for example, the string "Hello||World" when using pipe as a delimiter).

Yes, you can tell StrTok to skip empty tokens, but I actually need to handle empty tokens.

Any ideas how I can implement something like this (pseudocode)?


token = StrTok(stringToTokenize, delimiter)
while (token available)
{
print token
token = GetNextToken(stringToTokenize, delimiter)
}

probably not the best solution, but you could get the length of the entire string, each time you get a token you add the length of it (+separator) to another var, when you get a empty string you can compare the lengths to see if you are at the end


WordFind might do the trick. It returns a specific error level if the delimiter is not found.