Main Content

insertBefore

Insert string before substring in Requirements Table block

Since R2022b

Description

example

newStr = insertBefore(str,subStr,new) inserts the string new into the string str before the substring subStr. insertAfter inserts new before every occurrence of subStr. Use this operator in the Requirements Table block.

example

newStr = insertBefore(str,pos,new) inserts new into str before the character position pos.

Examples

expand all

In a Requirements Table block, create a requirement that inserts the substring " there" before the substring "," in the string "Hello, world!". The output is "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!".

In a Requirements Table block, create a requirement that inserts the substring " there" before the sixth character of the string "Hello, world!". The output is "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!".

Input Arguments

expand all

Input string, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Data Types: string

Substring, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Data Types: string

Character position, specified as a positive integer.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

New substring, specified as a string scalar. Enclose literal strings with double quotes.

Example: "Hello"

Data Types: string

Output Arguments

expand all

Output string, returned as a string scalar.

Limitations

  • This operator does not support the use of Simulink.Bus object fields.

Version History

Introduced in R2022b