Main Content

本页翻译不是最新的。点击此处可查看最新英文版本。

extractBefore

提取指定位置前的子字符串

自 R2021b 起

描述

示例

newStr = extractBefore(str,subStr) 返回 str 的子字符串,该子字符串在第一次出现子字符串 subStr 之前结束。

示例

newStr = extractBefore(str,pos) 返回在字符位置 pos 之前结束的 str 的子字符串。

注意

使用 C 语言作为动作语言的 Stateflow® 图不支持 extractBefore 运算符。要获得类似的功能,请使用 substr

示例

全部展开

从较长的字符串中提取子字符串 "Hello"

str = "Hello, world!";
newStr = extractBefore(str,", world");

Stateflow chart that uses the extractBefore operator in a state.

从较长的字符串中提取子字符串 "Hello"

str = "Hello, world!";
newstr = extractBefore(str,6);

Stateflow chart that uses the extractBefore operator in a state.

输入参数

全部展开

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

示例: "Hello"

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

示例: "Hello"

字符位置,指定为正整数。

限制

版本历史记录

在 R2021b 中推出