time | Calls | line |
---|
| | 1 | function s = erase(str, match)
|
| | 2 | %ERASE Remove content from text
|
| | 3 | % NEWSTR = ERASE(STR,PAT) removes occurrences of PAT from STR. If
|
| | 4 | % STR contains multiple occurrences of PAT, then ERASE removes all
|
| | 5 | % occurrences that do not overlap.
|
| | 6 | %
|
| | 7 | % STR must be text, which means it can be a string array, a character
|
| | 8 | % vector, or a cell array of character vectors. PAT can be text or a
|
| | 9 | % pattern array. PAT and STR need not have the same size.
|
| | 10 | % If PAT is a string array, a cell array, or a pattern array, then ERASE removes each
|
| | 11 | % occurrence of all the elements of PAT from STR.
|
| | 12 | %
|
| | 13 | % Examples:
|
| | 14 | % STR = "The quick brown fox";
|
| | 15 | % PAT = " quick";
|
| | 16 | % erase(STR,PAT)
|
| | 17 | %
|
| | 18 | % % returns "The brown fox"
|
| | 19 | %
|
| | 20 | % STR = 'Hello World';
|
| | 21 | % PAT = 'Hello ';
|
| | 22 | % erase(STR,PAT)
|
| | 23 | %
|
| | 24 | % % returns 'World'
|
| | 25 | %
|
| | 26 | % STR = "The answer is 42!";
|
| | 27 | % PAT = whitespacePattern + digitsPattern;
|
| | 28 | % erase(STR,PAT)
|
| | 29 | %
|
| | 30 | % % returns "The answer is!"
|
| | 31 | %
|
| | 32 | % See also STRREP, REGEXPREP, REPLACE, ERASEBETWEEN, PATTERN
|
| | 33 |
|
| | 34 | % Copyright 2016-2020 The MathWorks, Inc.
|
| | 35 |
|
< 0.001 | 5 | 36 | narginchk(2, 2);
|
| | 37 |
|
< 0.001 | 5 | 38 | if ~isTextStrict(str)
|
| | 39 | firstInput = getString(message('MATLAB:string:FirstInput'));
|
| | 40 | error(message('MATLAB:string:MustBeCharCellArrayOrString', firstInput));
|
< 0.001 | 5 | 41 | end
|
| | 42 |
|
< 0.001 | 5 | 43 | try
|
< 0.001 | 5 | 44 | s = string(str);
|
< 0.001 | 5 | 45 | s = s.erase(match);
|
< 0.001 | 5 | 46 | s = convertStringToOriginalTextType(s, str);
|
| | 47 |
|
| | 48 | catch E
|
| | 49 | throw(E)
|
< 0.001 | 5 | 50 | end
|
< 0.001 | 5 | 51 | end
|
Other subfunctions in this file are not included in this listing.