erase

Removes every occurrence of a substring from text.

Category: Language Fundamentals > Data Types

Syntax

newStr = erase(str, match)

Deletes each occurrence of match from str.

Description

erase searches for literal text, not patterns, and removes all non-overlapping matches. When match lists several strings, each one is removed from the text in the order given.

To delete by position rather than by content, use eraseBetween.

Input arguments

str
String array, character vector or cell array of character vectors.
match
Text to delete. A string array or cell array deletes several patterns, applied in turn.

Output arguments

newStr
Text of the same type and size as str, without the matches.

Example

Removing separators

erase("a-b-c", "-")
erase("hello world", ["lo", "wor"])
Output
ans = "abc"
ans = "hel ld"

See also

eraseBetween replace strrep extractBefore extractAfter