Main Content

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

replaceBetween

替换 Requirements Table模块中起点和终点之间的子字符串

自 R2022b 起

描述

示例

newStr = replaceBetween(str,startStr,endStr,new)str 中位于子字符串 startStrendStr 之间的子字符串替换为字符串 newreplaceBetween 不会替换 startStrendStr 本身。 new 的字符数可以与其替换的子字符串不同。在 Requirements Table模块中使用此运算符。

示例

newStr = replaceBetween(str,startPos,endPos,new) 替换 str 中位于 startPosendPos 字符位置之间的子字符串,包括这些位置上的字符。

示例

newStr = replaceBetween(___,Boundaries=bounds) 在运算符替换的子字符串中包含或排除前面语法中指定的边界。将 bounds 指定为 "inclusive""exclusive"

示例

全部展开

Requirements Table模块中,创建一个需求,将 "H""," 之间的字符串 "Hello, world!" 中的字符替换为子字符串 "owdy"。输出为 "Howdy, world!"

y = replaceBetween("Hello, world!","H",",","owdy")

This example shows a requirement that replaces the characters in the string "Hello, world!" between "H" and "," with the substring "owdy" and outputs the resulting string.

Requirements Table模块中,创建一个需求,将字符串 "Hello, world!" 的第二个和第六个字符之间的字符替换为子字符串 "owdy"。输出为 "Howdy, world!"

y = replaceBetween("Hello, world!",2,6,"owdy")

This example shows a requirement that replaces the characters between the second and sixth characters of the string "Hello, world!" with the substring "owdy" and outputs the resulting string.

Requirements Table模块中,创建一个需求,将 "H""o" 之间的字符串 "Hello, world!" 中的字符替换为子字符串 "Howdy"(包括边界)。输出为 "Howdy, world!"

y = replaceBetween("Hello, world!","H","o","Howdy",Boundaries="inclusive")

This example shows a requirement that replaces the characters in the string "Hello, world!" between "H" and "o" with the substring "Howdy", including the bounds, and outputs the resulting string.

Requirements Table模块中,创建一个需求,将 "H""o" 之间的字符串 "Hello, world!" 中的字符替换为子字符串 "Howdy"(不包括边界)。输出为 "HHowdyo, world!"

y = replaceBetween("Hello, world!","H","o","Howdy",Boundaries="exclusive")

This example shows a requirement that replaces the characters in the string "Hello, world!" between "H" and "o" with the substring "Howdy", excluding the bounds, and outputs the resulting string.

输入参数

全部展开

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

示例: "Hello"

数据类型: string

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

示例: "Hello"

数据类型: string

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

示例: "Hello"

数据类型: string

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

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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

数据类型: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

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

示例: "Hello"

数据类型: string

边界类型,指定为 "inclusive""exclusive"。当您将 bounds 设置为 "exclusive" 时,replaceBetween 仅替换边界之间的文本。当您将 bounds 设置为 "inclusive" 时,replaceBetween 也会替换边界本身。

数据类型: enumerated

输出参量

全部展开

输出字符串,以字符串标量形式返回。

限制

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

版本历史记录

在 R2022b 中推出

另请参阅

| |