Main Content

replaceBetween

Replace substrings between start and end points

Description

example

newStr = replaceBetween(str,startStr,endStr,new) replaces the substring in str between the substrings startStr and endStr with the string new. replaceBetween does not replace startStr and endStr themselves. new can have a different number of characters than the substring it replaces. Use this operator in the Requirements Table block.

example

newStr = replaceBetween(str,startPos,endPos,new) replaces the substring in str between the character positions startPos and endPos, including the characters at those positions.

example

newStr = replaceBetween(___,Boundaries=bounds) includes or excludes the boundaries specified in the previous syntaxes from the substring that the operator replaces. Specify bounds as "inclusive" or "exclusive".

Examples

expand all

In a Requirements Table block, create a requirement that replaces the characters in the string "Hello, world!" between "H" and "," with the substring "owdy". The output is "Howdy, world!".

y = replaceBetween("Hello, world!","H",",","owdy")

This example shows a requirement that replaces the characters in the string "Hello, world!" between "H" and "," with the substring "owdy" and outputs the resulting string.

In a Requirements Table block, create a requirement that replaces the characters between the second and sixth characters of the string "Hello, world!" with the substring "owdy". The output is "Howdy, world!".

y = replaceBetween("Hello, world!",2,6,"owdy")

This example shows a requirement that replaces the characters between the second and sixth characters of the string "Hello, world!" with the substring "owdy" and outputs the resulting string.

In a Requirements Table block, create a requirement that replaces the characters in the string "Hello, world!" between "H" and "o" with the substring "Howdy", including the bounds. The output is "Howdy, world!".

y = replaceBetween("Hello, world!","H","o","Howdy",Boundaries="inclusive")

This example shows a requirement that replaces the characters in the string "Hello, world!" between "H" and "o" with the substring "Howdy", including the bounds, and outputs the resulting string.

In a Requirements Table block, create a requirement that replaces the characters in the string "Hello, world!" between "H" and "o" with the substring "Howdy", excluding the bounds. The output is "HHowdyo, world!".

y = replaceBetween("Hello, world!","H","o","Howdy",Boundaries="exclusive")

This example shows a requirement that replaces the characters in the string "Hello, world!" between "H" and "o" with the substring "Howdy", excluding the bounds, and outputs the resulting string.

Input Arguments

expand all

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

Example: "Hello"

Data Types: string

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

Example: "Hello"

Data Types: string

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

Example: "Hello"

Data Types: string

Starting character position, specified as a positive integer.

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

Ending 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

Boundary type, specified as "inclusive" or "exclusive". When you set bounds to "exclusive", replaceBetween replaces only the text between the boundaries. When you set bounds to "inclusive", replaceBetween also replaces the boundaries themselves.

Data Types: enumerated

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