MATLAB Function Reference Previous page   Next Page
strfind

Find one string within another

Syntax

Description

k = strfind(str, pattern) searches the string str for occurrences of a shorter string, pattern, and returns the starting index of each such occurrence in the double array k. If pattern is not found in str, or if pattern is longer than str, then strfind returns the empty array [].

k = strfind(cellstr, pattern) searches each string in cell array of strings cellstr for occurrences of a shorter string, pattern, and returns the starting index of each such occurrence in cell array k. If pattern is not found in a string or if pattern is longer then all strings in the cell array, then strfind returns the empty array [], for that string in the cell array.

The search performed by strfind is case sensitive. Any leading and trailing blanks in pattern or in the strings being searched are explicitly included in the comparison.

Examples

Use strfind to find a two-letter pattern in string S:

Use strfind on a cell array of strings:

This means that 'wood' occurs at indices 10 and 23 in the first string and at indices 6 and 28 in the second.

See Also

findstr, strmatch, strtok, strcmp, strncmp, strcmpi, strncmpi, regexp, regexpi, regexprep


Previous page  streamtube strings Next page

© 1994-2005 The MathWorks, Inc.