Main Content

contains

Determine if string contains substring in Stateflow chart

Since R2021b

Description

tf = contains(str,substr) returns 1 (true) if the string str contains the substring substr, and returns 0 (false) otherwise.

example

tf = contains(str,substr,IgnoreCase=true) checks if str contains substr, ignoring any differences in letter case.

example

Note

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

Examples

expand all

Return a value of 0 (false) because the string "Hello, world!" does not contain the substring "World".

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

Stateflow chart that uses the contains operator in a state.

Return a value of 1 (true) because the string "Hello, world!" contains the substring "World" when you ignore case.

str = "Hello, world!";
substr = "World";
x = contains(str,substr,IgnoreCase=true);

Stateflow chart that uses the contains 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"

Limitations

  • This operator does not support the use of Stateflow structure fields or messages. For more information about structures in Stateflow, see Access Bus Signals.

Version History

Introduced in R2021b