Main Content

strfind

Find substring within a string in Stateflow chart

Since R2021b

Description

example

k = strfind(str,substr) searches the string str for occurrences of the substring substr. The operator returns a vector that contains the starting index of each occurrence of substr in str. The search is case-sensitive.

Note

The strfind operator is not supported in Stateflow® charts that use C as the action language.

Examples

expand all

Return a value of 8, the starting character position of the substring "world" in the string "Hello, world!".

str = "Hello, world!";
substr = "world";
x = strfind(str,substr);

Stateflow chart that uses the strfind operator in a state.

Input Arguments

expand all

Input string, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Substring, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Output Arguments

expand all

Starting character position of each occurrence of subStr in str, returned as a vector of doubles that contains the starting index of each occurrence of substr in str. If strfind does not find subStr, then k is an empty array.

Limitations

Version History

Introduced in R2021b