Main Content

substr

从字符串中提取子字符串

描述

示例

newStr = substr(str,pos,length) 返回 str 的子字符串,该子字符串从字符位置 pos 开始,长度为 length 个字符。使用从 0 开始的索引。

注意

仅在使用 C 语言作为动作语言的 Stateflow® 图中支持运算符 substr。在使用 MATLAB® 作为动作语言的图中,使用 extractAfterextractBefore

示例

全部展开

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

str = "Hello, world!";
newStr = substr(str,7,5);

Stateflow chart that uses the substr operator in a state.

提示

  • 使用从 0 开始的索引。

  • 用单引号或双引号将文字字符串引起来。

版本历史记录

在 R2018b 中推出