Main Content

eraseBetween

Delete substring between start and end points in Stateflow chart

Since R2021b

Description

newStr = eraseBetween(str,startStr,endStr) deletes the substring in str between the substrings startStr and endStr. eraseBetween does not delete startStr and endStr themselves.

example

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

example

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

example

Note

The eraseBetween operator is not supported in Stateflow® charts that use C as the action language.

Examples

expand all

Delete a substring to form the string "Hello!". By default, eraseBetween does not delete the boundary substrings.

str = "Hello, world!";
newStr = eraseBetween(str,"Hello","!");

Stateflow chart that uses the eraseBetween operator in a state.

Alternatively, use the option Boundaries="inclusive" to delete the boundary substrings.

str = "Hello, world!";
newStr = eraseBetween(str,",","d",new,Boundaries="inclusive");

Stateflow chart that uses the eraseBetween operator in a state.

Delete a substring to form the string "Hello!". By default, eraseBetween deletes the boundary characters.

str = "Hello, world!";
newStr = eraseBetween(str,6,12);

Stateflow chart that uses the erasebetween operator in a state.

Alternatively, use the Boundaries="exclusive" option to prevent deletion of the boundary characters.

str = "Hello, world!";
newStr = eraseBetween(str,5,13,new,Boundaries="exclusive");

Stateflow chart that uses the eraseBetween operator in a state.

Input Arguments

expand all

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

Example: "Hello"

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

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

Starting character position, specified as a positive integer.

Ending character position, specified as a positive integer.

Boundary type, specified as either "inclusive" or "exclusive". When you set bounds to "inclusive", replaceBetween erases the text between and including the boundaries. When you set bounds to "exclusive", replaceBetween erases the text only between the boundaries.

Limitations

  • This operator does not support the use of Stateflow structure fields or messages. For more information about structures in Stateflow, see Access Bus Signals.

Version History

Introduced in R2021b