7017
|
1 ## Copyright (C) 2006, 2007 William Poetra Yoga Hadisoeseno |
5674
|
2 ## |
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
5674
|
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 |
7016
|
16 ## along with Octave; see the file COPYING. If not, see |
|
17 ## <http://www.gnu.org/licenses/>. |
5674
|
18 |
|
19 ## -*- texinfo -*- |
|
20 ## @deftypefn {Function File} {} strtrunc (@var{s}, @var{n}) |
|
21 ## Truncate the character string @var{s} to length @var{n}. If @var{s} |
|
22 ## is a char matrix, then the number of columns are adjusted. |
|
23 ## |
|
24 ## If @var{s} is a cell array of strings, then the operation is performed |
|
25 ## on its members and the new cell array is returned. |
|
26 ## @end deftypefn |
|
27 |
|
28 function s = strtrunc (s, n) |
|
29 |
|
30 if (nargin != 2) |
6046
|
31 print_usage (); |
5674
|
32 endif |
|
33 |
|
34 if (ischar (s)) |
|
35 s_was_char = true; |
|
36 s = {s}; |
|
37 else |
|
38 s_was_char = false; |
|
39 endif |
|
40 |
|
41 if (iscellstr (s)) |
|
42 for i = 1:(numel (s)) |
|
43 s{i} = s{i}(:,1:(min (n, columns (s{i})))); |
|
44 endfor |
|
45 else |
|
46 error ("strtrunc: s must be a character string or a cell array of strings"); |
|
47 endif |
|
48 |
|
49 if (s_was_char) |
|
50 s = s{:}; |
|
51 endif |
|
52 |
|
53 endfunction |