Main Content

insertBefore

Insert string before substring

Since R2021b

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.

example

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

Note

The insertBefore operator is not supported in Stateflow® charts that use C as the action language.

Examples

expand all

Insert text to form the string "Hello there, world!".

str = "Hello, world!";
newStr = insertBefore(str,","," there");

Stateflow chart that uses the insertBefore operator in a state.

Insert text to form the string "Hello there, world!".

str = "Hello, world!";
newStr = insertBefore(str,6," there");

Stateflow chart that uses the insertBefore operator in a state.

Input Arguments

expand all

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

Example: "Hello"

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

Example: "Hello"

Character position, specified as a positive integer.

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

Example: "Hello"

Limitations

Version History

Introduced in R2021b