2313
|
1 ## Copyright (C) 1996 Kurt Hornik |
2325
|
2 ## |
2313
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
18 ## 02111-1307, USA. |
2268
|
19 |
3361
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} deblank (@var{s}) |
3894
|
22 ## Removes the trailing blanks and nulls from the string @var{s}. |
|
23 ## If @var{s} is a matrix, @var{deblank} trims each row to the |
|
24 ## length of longest string. |
3361
|
25 ## @end deftypefn |
2311
|
26 |
2355
|
27 ## Author: Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at> |
|
28 ## Adapted-By: jwe |
2314
|
29 |
2268
|
30 function t = deblank (s) |
2325
|
31 |
2268
|
32 if (nargin != 1) |
|
33 usage ("deblank (s)"); |
|
34 endif |
2325
|
35 |
2268
|
36 if (isstr (s)) |
|
37 |
3894
|
38 k = find (s != " " & s != "\0"); |
|
39 if (isempty (s) || isempty (k)) |
3175
|
40 t = ""; |
2268
|
41 else |
3894
|
42 t = s(:,1:ceil (max (k) / rows (s))); |
2268
|
43 endif |
|
44 |
|
45 else |
|
46 error ("deblank: expecting string argument"); |
|
47 endif |
|
48 |
|
49 endfunction |