Main Content

本页采用了机器翻译。点击此处可查看英文原文。

contains

确定字符串是否包含 Requirements Table模块中的子字符串

自 R2022b 起

描述

示例

如果字符串 str 包含子字符串 substr,则 tf = contains(str,substr) 返回 1 (true),否则返回 0 (false)。在 Requirements Table模块中使用此运算符。

示例

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

示例

全部展开

Requirements Table模块中,创建一个需求,输出字符串 "Hello, world!" 是否包含子字符串 "Hello"

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

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

Requirements Table模块中,创建一个需求,输出字符串 "Hello, world!" 是否包含子字符串 "Hello",无论大小写。

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.

输入参数

全部展开

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

示例: "Hello"

数据类型: string

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

示例: "Hello"

数据类型: string

限制

  • 该运算符不支持使用Simulink.Bus对象字段。

版本历史记录

在 R2022b 中推出

另请参阅

| |