主要内容

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

insertBefore

在 Requirements Table 模块中的子字符串前插入字符串

自 R2022b 起

描述

newStr = insertBefore(str,subStr,new) 将字符串 new 插入到字符串 str 中的子字符串 subStr 之前。insertAfter 在每个 new 出现的位置之前插入 subStr。在 Requirements Table 模块中使用此运算符。

示例

newStr = insertBefore(str,pos,new)new 插入到 str 中字符位置 pos 之前。

示例

示例

全部展开

Requirements Table 模块中,创建一个需求,将子字符串 " there" 插入字符串 "," 中的子字符串 "Hello, world!" 之前。输出为 "Hello there, world!"

y = insertBefore("Hello, world!",","," there")

This example shows a requirement that inserts the substring " there" before the substring "," in the string "Hello, world!".

Requirements Table 模块中,创建一个需求,将子字符串 " there" 插入到字符串 "Hello, world!" 的第六个字符之前。输出为 "Hello there, world!"

y = insertBefore("Hello, world!",6," there")

This example shows a requirement that inserts the substring " there" before the 6th character of the string "Hello, world!".

输入参数

全部展开

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

示例: "Hello"

数据类型: string

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

示例: "Hello"

数据类型: string

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

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

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

示例: "Hello"

数据类型: string

输出参量

全部展开

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

限制

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

版本历史记录

在 R2022b 中推出