Main Content

contains

确定 Stateflow 图中的字符串是否包含子字符串

自 R2021b 起

描述

如果字符串 str 包含子字符串 substr,则 tf = contains(str,substr) 返回 1 (true),否则返回 0 (false)。

示例

tf = contains(str,substr,IgnoreCase=true) 检查 str 是否包含 substr,忽略字母大小写差异。

示例

注意

使用 C 语言作为动作语言的 Stateflow® 图不支持 contains 运算符。

示例

全部展开

返回值 0 (false),因为字符串 "Hello, world!" 不包含子字符串 "World"

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

Stateflow chart that uses the contains operator in a state.

返回值 1 (true),因为在忽略大小写时字符串 "Hello, world!" 包含子字符串 "World"

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

Stateflow chart that uses the contains operator in a state.

输入参数

全部展开

输入字符串,指定为字符串标量。用双引号将文字字符串引起来。

示例: "Hello"

子字符串,指定为字符串标量。用双引号将文字字符串引起来。

示例: "Hello"

限制

  • 此运算符不支持使用 Stateflow 结构体字段或消息。有关 Stateflow 中结构体的详细信息,请参阅Access Bus Signals

版本历史记录

在 R2021b 中推出