Main Content

eraseBetween

Delete substring between start and end points

Description

example

newStr = eraseBetween(str,startPat,endPat) deletes all characters from str that occur between the substrings startPat and endPat, but does not delete startPat and endPat themselves. eraseBetween returns the remaining text as newStr.

example

newStr = eraseBetween(str,startPos,endPos) deletes all characters from str that occur between the positions startPos and endPos, including the characters at those positions.

example

newStr = eraseBetween(___,'Boundaries',bounds) forces the starts and ends specified in any of the previous syntaxes to be either inclusive when bounds is 'inclusive', and exclusive when bounds is 'exclusive'. For example, eraseBetween(str,startPat,endPat,'Boundaries','inclusive') deletes startPat, endPat, and all the text between them.

Note

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

Examples

expand all

Delete the substring that is between Hello and !.

h = "Hello, world!"
startPat = "Hello"
endPat = "!"
x = eraseBetween(h, startPat, endPat)

Stateflow chart that uses the erasebetween operator in a state.

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

Delete the substring that is between positions 6 and 12.

h = "Hello, world!"
x = eraseBetween(h, 6, 12)

Stateflow chart that uses the erasebetween operator in a state.

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

Delete text from string arrays with inclusive or exclusive boundaries.

h = "Hello, world!"
x = eraseBetween(h, 6, 12, "Boundaries', 'exclusive')

Stateflow chart that uses the erasebetween operator in a state.

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

h = "Hello, world!"
x = eraseBetween(h, 6, 12, "Boundaries', 'inclusive')

Stateflow chart that uses the erasebetween operator in a state.

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

Limitations

Introduced in R2021b