string.eraseBetween
string: newstr = eraseBetween (str, startPat, endPat)
string: newstr = eraseBetween (str, startPos, endPos)
string: newstr = eraseBetween (…, "Boundaries", bounds)
Erase content between start and end boundaries.
newstr = eraseBetween (str, startPat,
endPat) removes from each element of the string array str
the text that occurs between the substrings startPat and
endPat, keeping the boundary substrings themselves. startPat
and endPat can be string arrays, character vectors, or cell arrays
of character vectors. For each element, the first occurrence of
startPat is matched and then the first occurrence of endPat
that begins after it; if either boundary is not found, the element is
returned unchanged.
newstr = eraseBetween (str, startPos,
endPos) removes the text between the character positions
startPos and endPos, inclusive of the characters at those
positions. startPos and endPos must be positive integers
with startPos not exceeding endPos and both within the
length of the corresponding element of str.
newstr = eraseBetween (…, specifies whether the boundaries are included in or
excluded from the erased text. bounds can be either
"Boundaries",
bounds)"inclusive" or "exclusive". When boundaries are given
as substrings, the default is "exclusive" and the boundary
substrings are preserved; when given as positions, the default is
"inclusive" and the characters at those positions are erased.
startPat/endPat and startPos/endPos must either be scalars, applied to every element of str, or be of the same size as str and applied element-wise. newstr is a string array of the same size as str. Missing values in str are preserved.
Source Code: string
eraseBetween deletes the text between two delimiters, keeping the delimiters themselves.
s = string ({'a<secret>b'; 'x<hidden>y'})
s =
2x1 string array
"a<secret>b"
"x<hidden>y"
eraseBetween (s, '<', '>')
ans =
2x1 string array
"a<>b"
"x<>y"