AT&T Home | AT&T Labs | Research
AT&T Labs, Inc. - Research

The Yoix® Scripting Language

Home | What's New | Grammar | Documentation | Download | License | YDAT | YWAIT | Byzgraf | FAQs
strtok (String str1, String str2) yoix.string
 
Finds the first token in the null-terminated string str1 delimited by one of the characters from the null-terminated string str2. strtok creates a new string from the delimited sub-string and returns that string, or NULL when no tokens remain.

strtok remembers its position in the current string and uses it on subsequent calls made with the same string, str1, as the first argument. Two adjacent delimiters in str1 causes an empty string to be returned, so a sequence of calls splits str1 into tokens delimited by characters from str2. The separator string str2 can be different on each call. String str1 is trashed by strtok and should not be modified outside strtok if the tokenizing is expected to continue properly.
 
 Example:   The program,
import yoix.stdio.*;
import yoix.string.*;

String str1 = "Say what?";
String str2 = "Hello there, world";
String delim = " ,?";
String result;

while ((result = strtok(str1, delim)) != NULL) {
    printf("|%s| ", result);
    while ((result = strtok(str2, delim)) != NULL) {
        printf("|%s| ", result);
    }
}
printf("\n");
prints
|Say| |Hello| |there| || |world| |what| ||
on standard output.
 
 Return:   String
 
 See Also:   strcasecmp, strcat, strchr, strcmp, strcpy, strcspn, strdel, strdup, strfmt, strins, strjoin, strlen, strncasecmp, strncat, strncmp, strncpy, strpbrk, strrchr, strrstr, strsplit, strspn, strstr

 

Yoix is a registered trademark of AT&T Intellectual Property.