Main Content

contains

Determine if string contains substring

Description

example

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.

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

Version History

Introduced in R2021b