contents   index   previous   next



Clib.strtok(srcStr, delimiterStr)


srcStr - source string consisting of delimited tokens.


delimiterStr - string of delimiter characters that separate tokens.



string - a token, a substring, in srcStr, else null if there is not a token or if there are no more tokens.



This method is unusual. The parameter srcStr is a string that consists of text tokens, substrings, separated by delimiter characters found in delimiterStr. The parameter srcStr may be altered during the first and subsequent calls to Clib.strtok().


On the first call to Clib.strtok(), srcStr points to the string to tokenize and delimiterStr is a set of characters which are used to separate tokens in the source string. The first call, such as:


token = Clib.strtok(srcStr, delimiterStr)


returns a variable pointing to the srcStr array and based at the first character of the first token in srcStr. On subsequent calls, such as


token = Clib.strtok(null, delimiterStr)


the first argument is null and Clib.strtok() will continue through srcStr returning subsequent tokens.


The initial variable receiving tokens must remain valid throughout following calls that use null. If the variable is changed in any way, a subsequent use of Clib.strtok() must first use the syntax form in which the new string, not null, is passed as a first parameter.


This method returns null if there are no more tokens; otherwise returns srcStr array variable based at the next token in srcStr.






// The following code:


var source = 

   " Little   John,,,Eats ?? crackers;;;! ";

var token = Clib.strtok(source,", ");

while(null != token)



   token = Clib.strtok(null,";?, ");



// produces the following list of tokens.

//  Little 

//  John 

//  Eats 

//  crackers 

//  !