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.

Syntax

CStrTok:SetDelimiter( sDelim )

bullet.gif    sDelim is a string containing the delimiter characters.

Remarks

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.

Example

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.

sDelim = ", \t\r\n"

-- delimiters comma, blank, tab, new line, and return

T = new_strtok( sStr, sDelim )

-- create a new CStrTok object initialized to target

 

-- string sStr and delimiters sDelim

...

-- parse some of sStr and work with the pieces

sNewDelim = ",\t\r\n"

-- stop using blank as a delimiter

T:SetDelimiter( sStr, sNewDelim )

-- change to new delimiters

 

 

  ...

-- continue parsing the string

T:delete()

-- delete the object and its associated memory.

Related Topics

CStrTok, new, Next, Init


Mira Pro x64 Script User's Guide, Copyright Ⓒ 2023 Mirametrics, Inc. All Rights Reserved.