Find all characters up to but not including the first character which is in the string delim. If rem is requested, it contains the remainder of the string, starting at the first deliminator. Leading delimiters are ignored. If delim is not specified, space is assumed.
The following code
strtok("this is the life") % split at the first space, returning "this"
Produces the following output
ans = this
The following code
s = "14*27+31" while 1 [t,s] = strtok(s, "+-*/"); printf("<%s>", t); if isempty(s), break; endif printf("<%s>", s(1)); endwhile printf("\n"); % ---------------------------------------------------- % Demonstrates processing of an entire string split on % a variety of delimiters. Tokens and delimiters are % printed one after another in angle brackets. The % string is:
Produces the following output
s = 14*27+31 <14><*><27><+><31>