strtok

Splits the string s at the given delimiter delim and returns a cell array whose elements are the substrings of string s.

Syntax

R = strtok(s)

R = strtok(s, delim)

[R, Rem] = strtok(s, delim)

Inputs

s
Type: string
delim (optional)
Delimiter. Whitespace is the default delimiter.
Type: string

Outputs

R
Tokenized result.
Type: string
Rem (optional)
Remainder after the input string is tokenized.
Type: string

Examples

Tokenize string with default delimiter:
R = strtok(' Tokenize this string')
R = Tokenize
Tokenize string with user-specified delimiter:
R = strtok('12345 + 678 - 9', '+-')
R = 12345
Tokenize string with user-specified delimiter and remainder:
[R, Rem] = strtok('45 * 12345 + 678 - 9', '+-')
R = 45 * 12345
Rem = + 678 - 9

Comments

If there is no delimiter delim specified, whitespace is used as the default delimiter. If a remainder Rem is specified, Rem will contain the remainder of the string s along with the first character of the delimiter delim, if specified.