主要内容

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

replaceBetween

R2025b

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

自 R2022b 起

描述

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

示例

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

示例

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

示例

示例

全部展开

在 Requirements Table 模块中,创建一个需求,将 "Hello, world!" 和 "H" 之间的字符串 "," 中的字符替换为子字符串 "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 模块中,创建一个需求,将 "Hello, world!" 和 "H" 之间的字符串 "o" 中的字符替换为子字符串 "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 模块中,创建一个需求,将 "Hello, world!" 和 "H" 之间的字符串 "o" 中的字符替换为子字符串 "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 中推出

另请参阅

| |