Main Content

strrep

Find and replace substrings in Requirements Table block

Since R2022b

Description

newStr = strrep(str,old,new) replaces instances of the substring old that occur in the string str with the substring new. Use this operator in the Requirements Table block.

example

Examples

expand all

In a Requirements Table block, create a requirement that replaces the substring "Hello" with the substring "Howdy".

y = strrep("Hello, world!","Hello","Howdy")

This example shows a requirement that replaces the substring "Hello" with the substring "Howdy".

Input Arguments

expand all

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

Example: "Hello"

Data Types: string

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

Example: "Hello"

Data Types: string

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.

Algorithms

The strrep operator replaces overlapping substrings. For example, strrep("abc 2 def 22 ghi 222 jkl 2222","22","*") returns "abc 2 def * ghi ** jkl ***". To replace only sequential substrings, use replace. For more information, see Replace Repeated Pattern.

Version History

Introduced in R2022b