Mercurial > hg > octave-nkf
comparison scripts/strings/strtrim.m @ 12876:29cd5a828bb2
strtrim.m: Don't remove nuls (\0) from string.
* strtrim.m: Stop removing nuls (\0) to be compatible with Matlab.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 23 Jul 2011 19:25:03 -0700 |
parents | d5d3f04a645f |
children | 1c71c9bf0570 |
comparison
equal
deleted
inserted
replaced
12875:787a84da70a6 | 12876:29cd5a828bb2 |
---|---|
16 ## along with Octave; see the file COPYING. If not, see | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} strtrim (@var{s}) | 20 ## @deftypefn {Function File} {} strtrim (@var{s}) |
21 ## Remove leading and trailing whitespace and nulls from @var{s}. If | 21 ## Remove leading and trailing whitespace from @var{s}. If |
22 ## @var{s} is a matrix, @var{strtrim} trims each row to the length of | 22 ## @var{s} is a matrix, @var{strtrim} trims each row to the length of |
23 ## longest string. If @var{s} is a cell array, operate recursively on | 23 ## longest string. If @var{s} is a cell array, operate recursively on |
24 ## each element of the cell array. For example: | 24 ## each element of the cell array. For example: |
25 ## | 25 ## |
26 ## @example | 26 ## @example |
44 print_usage (); | 44 print_usage (); |
45 endif | 45 endif |
46 | 46 |
47 if (ischar (s)) | 47 if (ischar (s)) |
48 | 48 |
49 k = find (! isspace (s) & s != "\0"); | 49 k = find (! isspace (s)); |
50 if (isempty (s) || isempty (k)) | 50 if (isempty (s) || isempty (k)) |
51 s = ""; | 51 s = ""; |
52 else | 52 else |
53 s = s(:, ceil (min (k) / rows (s)):ceil (max (k) / rows (s))); | 53 s = s(:, ceil (min (k) / rows (s)):ceil (max (k) / rows (s))); |
54 endif | 54 endif |
55 | 55 |
56 elseif (iscell(s)) | 56 elseif (iscell(s)) |
57 | 57 |
58 s = regexprep (s, "^[\\s\v\\0]+|[\\s\v\\0]+$", ''); | 58 s = regexprep (s, "^[\\s\v]+|[\\s\v]+$", ''); |
59 | 59 |
60 else | 60 else |
61 error ("strtrim: S argument must be a string"); | 61 error ("strtrim: S argument must be a string"); |
62 endif | 62 endif |
63 | 63 |