Main Content

contains

Determine if string contains substring in Requirements Table block

Since R2022b

Description

tf = contains(str,substr) returns 1 (true) if the string str contains the substring substr, and returns 0 (false) otherwise. Use this operator in the Requirements Table block.

example

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

example

Examples

expand all

In a Requirements Table block, create a requirement that outputs whether the string "Hello, world!" contains the substring "Hello".

y = contains("Hello, world!","Hello")

This image shows a requirement that outputs whether the string "Hello, world" contains the substring "Hello".

In a Requirements Table block, create a requirement that outputs whether the string "Hello, world!" contains the substring "Hello", regardless of case.

y = contains("Hello, world!","hello",IgnoreCase=true)

This image shows a requirement that outputs whether the string "Hello, world" contains the substring "hello" regardless of case.

Input Arguments

expand all

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

Example: "Hello"

Data Types: string

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

Example: "Hello"

Data Types: string

Limitations

  • This operator does not support the use of Simulink.Bus object fields.

Version History

Introduced in R2022b