Main Content

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

startsWith

确定字符串是否以 Requirements Table模块中的子字符串开头

自 R2022b 起

描述

示例

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

示例

tf = startsWith(str,substr,IgnoreCase=true) 检查 str 是否以 substr 开头,忽略字母大小写差异。

示例

全部展开

Requirements Table模块中,创建一个需求,检查字符串 "Hello, world!" 是否以子字符串 "Hello," 开头。

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

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

Requirements Table模块中,创建一个需求,检查字符串 "Hello, world!" 是否以子字符串 "hello," 开头,无论大小写。

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

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

输入参数

全部展开

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

示例: "Hello"

数据类型: string

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

示例: "Hello"

数据类型: string

限制

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

版本历史记录

在 R2022b 中推出

另请参阅

| |