This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

findstr

(Not recommended) Find string within another, longer string

findstr is not recommended. Use contains or strfind instead.

Syntax

k = findstr(str1, str2)

Description

k = findstr(str1, str2) searches the longer of the two input arguments for any occurrences of the shorter argument, 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 input arguments str1 and str2 can be character vectors or string scalars.

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

Unlike the contains or strfind functions, 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 arguments is the longer one.

Examples

s = 'Find the starting indices of the shorter character vector.';

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

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

Introduced before R2006a