Mercurial > octave-nkf
comparison scripts/strings/strtrunc.m @ 8442:502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Mon, 05 Jan 2009 08:11:03 +0100 |
parents | a1dbe9d80eee |
children | eb63fbe60fab |
comparison
equal
deleted
inserted
replaced
8441:cc3ac5eb6be3 | 8442:502e58a0d44f |
---|---|
17 ## <http://www.gnu.org/licenses/>. | 17 ## <http://www.gnu.org/licenses/>. |
18 | 18 |
19 ## -*- texinfo -*- | 19 ## -*- texinfo -*- |
20 ## @deftypefn {Function File} {} strtrunc (@var{s}, @var{n}) | 20 ## @deftypefn {Function File} {} strtrunc (@var{s}, @var{n}) |
21 ## Truncate the character string @var{s} to length @var{n}. If @var{s} | 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. | 22 ## is a char matrix, then the number of columns is adjusted. |
23 ## | 23 ## |
24 ## If @var{s} is a cell array of strings, then the operation is performed | 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. | 25 ## on its members and the new cell array is returned. |
26 ## @end deftypefn | 26 ## @end deftypefn |
27 | 27 |
49 if (s_was_char) | 49 if (s_was_char) |
50 s = s{:}; | 50 s = s{:}; |
51 endif | 51 endif |
52 | 52 |
53 endfunction | 53 endfunction |
54 | |
55 %!error <Invalid call to strtrunc> strtrunc (); | |
56 %!error <s must be a character string or a cell array of strings> strtrunc (1, 1) | |
57 %!assert (strtrunc("abcdefg", 4), "abcd"); | |
58 %!assert (strtrunc("abcdefg", 10), "abcdefg"); | |
59 %!assert (strtrunc({"abcdef", "fedcba"}, 3), {"abc", "fed"}); |