comparison scripts/strings/deblank.m @ 5462:74804828df1a

[project @ 2005-09-22 18:36:22 by jwe]
author jwe
date Thu, 22 Sep 2005 18:36:23 +0000
parents ec8c33dcd1bf
children 75a828280d68
comparison
equal deleted inserted replaced
5461:8d8fc8eff9e6 5462:74804828df1a
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 ## 02110-1301, USA. 18 ## 02110-1301, USA.
19 19
20 ## -*- texinfo -*- 20 ## -*- texinfo -*-
21 ## @deftypefn {Function File} {} deblank (@var{s}) 21 ## @deftypefn {Function File} {} deblank (@var{s})
22 ## Removes the trailing blanks and nulls from the string @var{s}. 22 ## Remove trailing blanks and nulls from @var{s}. If @var{s}
23 ## If @var{s} is a matrix, @var{deblank} trims each row to the 23 ## is a matrix, @var{deblank} trims each row to the length of longest
24 ## length of longest string. 24 ## string. If @var{s} is a cell array, operate recursively on each
25 ## element of the cell array.
25 ## @end deftypefn 26 ## @end deftypefn
26 27
27 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> 28 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
28 ## Adapted-By: jwe 29 ## Adapted-By: jwe
29 30
30 function t = deblank (s) 31 function s = deblank (s)
31 32
32 if (nargin != 1) 33 if (nargin != 1)
33 usage ("deblank (s)"); 34 usage ("deblank (s)");
34 endif 35 endif
35 36
36 if (ischar (s)) 37 if (ischar (s))
37 38
38 k = find (! isspace (s) & s != "\0"); 39 k = find (! isspace (s) & s != "\0");
39 if (isempty (s) || isempty (k)) 40 if (isempty (s) || isempty (k))
40 t = ""; 41 s = "";
41 else 42 else
42 t = s(:,1:ceil (max (k) / rows (s))); 43 s = s(:,1:ceil (max (k) / rows (s)));
43 endif 44 endif
45
46 elseif (iscell(s))
47
48 for i = 1:numel (s)
49 s{i} = deblank (s{i});
50 endfor
44 51
45 else 52 else
46 error ("deblank: expecting string argument"); 53 error ("deblank: expecting string argument");
47 endif 54 endif
48 55