strfind
Find strings within other strings
Description
searches k
= strfind(str
,pat
)str
for occurrences of pat
. The
output, k
, indicates the starting index of each occurrence of
pat
in str
. If
pat
is not found, then strfind
returns
an empty array, []
. The strfind
function
executes a case-sensitive search.
If
str
is a character vector or a string scalar, thenstrfind
returns a vector of typedouble
.If
str
is a cell array of character vectors or a string array, thenstrfind
returns a cell array of vectors of typedouble
.
forces k
= strfind(str
,pat
,'ForceCellOutput',cellOutput
)strfind
to return k
as a cell array
when cellOutput
is true, even when str
is a
character vector.
Examples
Input Arguments
Output Arguments
Tips
If
pat
is a character vector or string scalar with no characters (''
or""
), thenstrfind
returns an empty array.The
contains
function is recommended for finding patterns within string arrays.