strtok
Selected parts of strings
Description
parses token
= strtok(str
)str
from
left to right, using whitespace characters as delimiters, and returns
part or all of the text in token
. First, strtok
ignores
any leading whitespace in str
. Then, strtok
starts
at the first character that is not whitespace, and includes all characters
up to, but not including, the next whitespace character. strtok
returns
that part of the text in token
. If strtok
does
not find any whitespace to use as a delimiter, then token
includes
all characters up to, and including, the end of str
.
parses token
= strtok(str
,delimiters
)str
using
the characters in delimiters
. If delimiters
includes
more than one character, then strtok
treats each
character in delimiters
as a separate delimiter.
Because the delimiters are individual characters, delimiters
can
be any size, and the characters within delimiters
can
be in any order.
In this syntax, whitespace characters are not delimiters unless
you include them within delimiters
.
[
returns the remaining text, if
any, in token
,remain
]
= strtok(___)remain
. If strtok
finds
a delimiter, then it is included at the start of remain
.
If strtok
finds no delimiters in str
,
then it returns the whole of str
, except for leading
delimiters, in token
, and remain
has
no characters. You can use this syntax with any of the input arguments
of the previous syntaxes.
Examples
Input Arguments
Output Arguments
Tips
Do not specify an escape-character sequence as a delimiter. strtok
does
not translate escape character sequences. Instead, you can use the char
function
to specify such characters. For example, to specify a tab as a delimiter
use char(9)
instead of '\t'
.
Extended Capabilities
Version History
Introduced before R2006a