| MATLAB Function Reference | ![]() |
Find one string within another
Syntax
Description
k = strfind(str,pattern)
searches the string, str, for occurrences of a shorter string, pattern, returning 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, [].
The search performed by strfind is case sensitive. Any leading and trailing blanks in either str or pattern are explicitly included in the comparison.
Use the function findstr, if you are not certain which of the two input strings is the longer one.
Examples
s = 'Find the starting indices of the pattern string'; strfind(s,'in') ans = 2 15 19 45 strfind(s,'In') ans = [] strfind(s,' ') ans = 5 9 18 26 29 33 41
See Also
findstr, strmatch, strtok, strcmp, strncmp, strcmpi, strncmpi, regexp, regexpi, regexprep
| streamtube | strings | ![]() |