wwUtils::TokenizeString

String tokenizing function that extracts and replaces tokens found by extracting value between a start and end delimiter. The extracted values are returned in a sequential collection.

If the source is passed by reference the source is modified with a tokenized placeholder.

Tokenized strings look like this (#@# delimiter): IEnumerable#@#1#@# List, Field field, List#@#2#@# fieldList

o.TokenizeString(@lcSource,lcStart,lcEnd,lcDelimiter)

Parameters

@lcSource
The input string that is to be tokenized. Pass by reference if you want to receive back the string with the tokens embedded.

lcStart
A starting search string which is extracted for a token.

lcEnd
An end search string which is extracted for a token.

lcDelimiter
Optional - delimiter for embedded tokens. The default is #@#.

String tokens are embedded in the format (based on #@# delimiter):
Some text #@#1#@# some other text #@#2#@#.

Example

lcParameters = "IEnumerable<Field,bool> List, Field field, List<Field,int> fieldList"
? "Original: " 
? lcParameters
?
*** Creates tokens in the lcSource String and returns a collection of the 
*** tokens.
loTokens = TokenizeString(@lcParameters,"<",">")

? lcParameters
* IEnumerable#@#1#@# List, Field field, List#@#2#@# fieldList

FOR lnX = 1 TO loTokens.Count
   ? loTokens[lnX]
ENDFOR
?
? "Tokenized string: " + lcParameters
?
? "Parsed parameters:"
*** Now parse the parameters
lnCount = ALINES(laParms,lcParameters,",")
FOR lnX = 1 TO lnCount
   *** Detokenize indvidual parameters
   laParms[lnX] = DetokenizeString(laParms[lnX],loTokens)
   ? laParms[lnX]
ENDFOR

?
? "Detokenized String (should be same as original):"
*** or you can detokenize the entire string at once
? DetokenizeString(lcParameters,loTokens)

See also:

Class wwUtils

© West Wind Technologies, 1996-2024 • Updated: 11/19/15
Comment or report problem with topic