time | Calls | line |
---|
| | 1 | function s = strip(str, varargin)
|
| | 2 | %STRIP Remove leading and trailing whitespaces
|
| | 3 | % NEWSTR = STRIP(STR) removes all consecutive whitespace characters from
|
| | 4 | % the beginning and the end of STR. Whitespace is defined as any sequence
|
| | 5 | % of whitespace characters such as spaces, tabs, and newlines.
|
| | 6 | %
|
| | 7 | % STR can be a string array, character vector, or cell array of character
|
| | 8 | % vectors. If STR is a string array or cell array, then STRIP removes
|
| | 9 | % leading and trailing whitespace from each element of STR.
|
| | 10 | %
|
| | 11 | % NEWSTR = STRIP(STR,SIDE) removes whitespace characters from the
|
| | 12 | % specified SIDE. SIDE can be 'left', 'right', or 'both'. The default
|
| | 13 | % value of SIDE is 'both'.
|
| | 14 | %
|
| | 15 | % NEWSTR = STRIP(STR,PAD_CHARACTER) removes PAD_CHARACTER from STR.
|
| | 16 | % PAD_CHARACTER must be exactly one character.
|
| | 17 | %
|
| | 18 | % NEWSTR = STRIP(STR,SIDE,PAD_CHARACTER) removes PAD_CHARACTER from the
|
| | 19 | % specified SIDE.
|
| | 20 | %
|
| | 21 | % Example:
|
| | 22 | %
|
| | 23 | % STR = ["moustache ";
|
| | 24 | % " goatee";
|
| | 25 | % " beard "];
|
| | 26 | % strip(STR)
|
| | 27 | %
|
| | 28 | % returns
|
| | 29 | %
|
| | 30 | % "moustache"
|
| | 31 | % "goatee"
|
| | 32 | % "beard"
|
| | 33 | %
|
| | 34 | % Example:
|
| | 35 | % strip("C:\Temp\Files\",'right','\')
|
| | 36 | %
|
| | 37 | % returns
|
| | 38 | %
|
| | 39 | % "C:\Temp\Files"
|
| | 40 | %
|
| | 41 | % See also PAD, STRING, REPLACE
|
| | 42 |
|
| | 43 | % Copyright 2016 The MathWorks, Inc.
|
| | 44 |
|
< 0.001 | 2 | 45 | narginchk(1, 3);
|
| | 46 |
|
< 0.001 | 2 | 47 | if ~isTextStrict(str)
|
| | 48 | firstInput = getString(message('MATLAB:string:FirstInput'));
|
| | 49 | error(message('MATLAB:string:MustBeCharCellArrayOrString', firstInput));
|
< 0.001 | 2 | 50 | end
|
| | 51 |
|
< 0.001 | 2 | 52 | try
|
< 0.001 | 2 | 53 | s = string(str);
|
| | 54 |
|
< 0.001 | 2 | 55 | if nargin == 1
|
< 0.001 | 2 | 56 | s = s.strip();
|
| | 57 | else
|
| | 58 | s = s.strip(varargin{:});
|
< 0.001 | 2 | 59 | end
|
| | 60 |
|
< 0.001 | 2 | 61 | s = convertStringToOriginalTextType(s, str);
|
| | 62 |
|
| | 63 | catch E
|
| | 64 | throw(E)
|
< 0.001 | 2 | 65 | end
|
< 0.001 | 2 | 66 | end
|
Other subfunctions in this file are not included in this listing.