CStrTok:new CStrTok:SetDelimiter

CStrTok:Next


The Next method steps through the target string, returning the next token from the target string. If there are no more tokens remaining, nil is returned. As each piece of the target string is parsed, you use it or you might store it in an array for later use (see the Example, below).

Syntax

sStr = CStrTok:Next()

bullet.gif    sStr is the next string token from the target string.

Example

The following script parses the string sStr into pieces delimited by ", \t" (comma, blank, and tab characters). In this example, the pieces are stored in a table (an array) named A for later use.

T = new_strtok( sStr, ", \t" )

-- create a new CStrTok object initialized to the target

 

-- string sStr and the delimiters.

A = { }

-- create table A to hold the string tokens

n = 0

-- start index with no tokens counted

while true do

-- loop until there are no more tokens

  str = T:Next()

-- get the next token

  if str ~= nil then

-- if a token exists

    n = n + 1

-- advance to the next table index

    A[n] = str

-- add the token string to the table

  else

 

    break

-- no more tokens, break out of the loop

  end

-- end of test

end

-- end of parsing loop

  ...

-- work with the string pieces in array A.

T:delete()

-- delete the object and its associated memory.

Related Topics

CStrTok, new, Next, Init


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