MATLAB Function Reference Previous page   Next Page
strtok

Return selected parts of string

Syntax

Description

token = strtok('str') uses the default delimiters, the white-space characters. These include tabs (ASCII 9), carriage returns (ASCII 13), and spaces (ASCII 32). Any leading white-space characters are ignored. If str is a cell array of strings, token is a cell array of tokens.

token = strtok('str', delimiter) returns the first token in the text string str, that is, the first set of characters before a delimiter is encountered. The vector delimiter contains valid delimiter characters. Any leading delimiters are ignored. If str is a cell array of strings, token is a cell array of tokens.

[token, rem] = strtok(...) returns the remainder rem of the original string. The remainder consists of all characters from the first delimiter on. If str is a cell array of strings, token is a cell array of tokens, and rem is a character array.

Examples

Example 1

This example uses the default white-space delimiter:

Example 2

Take a string of HTML code and break it down into segments delimited by the < and > characters. Write a while loop to parse the string and print each segment:

Here is the output:

Example 3

Using strtok on a cell array of strings returns a cell array of strings in token and a character array in rem:

Here is the output:

See Also

findstr, strmatch


Previous page  strrep strtrim Next page

© 1994-2005 The MathWorks, Inc.