Main Content

findstr

(Not recommended) Find string within another, longer string

findstr is not recommended. Use contains or strfind instead.

Description

example

k = findstr(str1,str2) searches the longer of the two input arguments for any occurrences of the shorter argument and returns the starting index of each occurrence. If it finds no occurrences, then findstr returns the empty array, []. The input arguments str1 and str2 can be character vectors or string scalars.

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

Unlike with 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

collapse all

Create a string array. Use strmatch with the third input "exact" to find elements of strarray that exactly match the text "max".

strarray = ["max" "minimax" "maximum"];
x = strmatch("max",strarray,"exact")
x = 1

Input Arguments

collapse all

Text to compare, specified as a character vector or string scalar. strfind searches the longer of the two inputs for any occurrences of the shorter argument.

Data Types: char | string

Introduced before R2006a