Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

findstr - Find string within another, longer string

Syntax

k = findstr(str1, str2)

Description

k = findstr(str1, str2) searches the longer of the two input strings for any occurrences of the shorter string, returning the starting index of each such occurrence in the double array k. If no occurrences are found, then findstr returns the empty array, [].

The search performed by findstr is case sensitive. Any leading and trailing blanks in either input string are explicitly included in the comparison.

Unlike the strfind function, the order of the input arguments to findstr is not important. This can be useful if you are not certain which of the two input strings is the longer one.

Examples

s = 'Find the starting indices of the shorter string.';

findstr(s, 'the')
ans =
     6    30

findstr('the', s)
ans =
     6    30

See Also

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

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS