Main Content

contains

Determine if pattern is in a string

Description

example

TF = contains(str,pat) returns 1 (true) if str contains the specified pattern, and returns 0 (false) otherwise.

Note

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

Examples

expand all

Return a 1(true) if the string contains the pattern.

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

Stateflow chart that uses the contains operator in a state.

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

Limitations

Introduced in R2021b