Main Content

replace

Find and replace one or more substring

Description

newStr = replace(str,old,new) replaces all occurrences of the substring old with new.

Note

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

Examples

expand all

h = "Hello, world!"
old = "Hello"
new = "Howdy"
x = replace(h, old, new)

Stateflow chart that uses the replace operator in a state.

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

Limitations

Introduced in R2021b