Main Content

insertBefore

Insert string before specified substring

Description

example

newStr = insertBefore(str,pat,newText) inserts newText into str before the substring specified by pat and returns the result as newStr. If pat occurs multiple times in str, then insertBefore inserts newText before every occurrence of pat.

example

newStr = insertBefore(str,pos,newText) inserts the text specified by newText into str before the position specified by pos.

Note

Only Stateflow® charts that use MATLAB® as the action language support the insertBefore operator.

Examples

expand all

Insert the text there before a substring.

h = "Hello, world!"
pat = ","
x = insertBefore(h, pat, " there")

Stateflow chart that uses the insertbefore operator in a state.

Results from stateflow chart that uses the insertafter operator in a state.

Insert text there before a position.

h = "Hello, world!"
x = insertAfter(h, 5, " there")

Stateflow chart that uses the insertbefore operator in a state.

Results from stateflow chart that uses the insertbefore operator in a state.

Limitations

Introduced in R2021b