CStrTok:SetDelimiter
The SetDelimiter method initializes the CStrTok object to a new set of delimiters for parsing the existing target string. Use this method to change delimiters after you have started parsing the target string. In that case, subsequent calls to Next will return tokens based on the new delimiters.
CStrTok:SetDelimiter( sDelim )
Suppose you need to parse a target string like the following:
"Image 1: obj 24___14:05:46.254 -15:14:51.3 15.24"
where ___ refers to a tab. The first token is a string like the one shown above that may contain a blank or a colon character and is delimited by a tab character. However, later tokens may use a blank or colon as a delimiter. To parse the target string, you have 2 choices:
Do not use a colon or blank delimiter and parse the entire string. Then setup separate instances of CStrTok with colons and blanks to parse the tokens (except for the first one) into further tokens.
Setup the CStrTok using delimiters that apply to the first token, including a tab, and call Next to get the first token. Then call SetDelimiter to include all delimiters that apply to the remainder of the target string and repeatedly call Next to parse it.
The following script parses two strings sStr and sNewStr into pieces delimited by delimiter characters sDelim. This also could be done using two instances of CStrTok.
|
-- delimiters comma, blank, tab, new line, and return |
|
-- create a new CStrTok object initialized to target |
|
-- string sStr and delimiters sDelim |
|
-- parse some of sStr and work with the pieces |
|
-- stop using blank as a delimiter |
|
-- change to new delimiters |
|
|
|
-- continue parsing the string |
|
-- delete the object and its associated memory. |