Main Content

strfind

Find strings within other strings

Description

example

k = strfind(str,pat) searches 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.

Note

Only Stateflow® charts that use MATLAB® as the action language support the startsWith operator.

Examples

expand all

Find the starting indices of substrings in a string.

h = "Hello, world!"
pat = "world"
x = strfind(h, pat)

Stateflow chart that uses the strfind operator in a state.

Results from stateflow chart that uses the strfind operator in a state.

Limitations

Introduced in R2021b