5372
|
1 ## Copyright (C) 1996, 1997 John W. Eaton |
|
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 |
|
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, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
|
19 |
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} strncmp (@var{s1}, @var{s2}, @var{n}) |
5674
|
22 ## Return 1 if the first @var{n} characters of character strings @var{s1} |
|
23 ## and @var{s2} are the same, and 0 otherwise. |
|
24 ## |
|
25 ## If either @var{s1} or @var{s2} is a cell array of strings, then an array |
|
26 ## of the same size is returned, containing the values described above for |
|
27 ## every member of the cell array. The other argument may also be a cell |
|
28 ## array of strings (of the same size or with only one element), char matrix |
|
29 ## or character string. |
5372
|
30 ## |
|
31 ## @strong{Caution:} For compatibility with @sc{Matlab}, Octave's strncmp |
5674
|
32 ## function returns 1 if the character strings are equal, and 0 otherwise. |
|
33 ## This is just the opposite of the corresponding C library function. |
|
34 ## @seealso{strcmp, strcmpi, strncmpi} |
5372
|
35 ## @end deftypefn |
|
36 |
|
37 function retval = strncmp (s1, s2, n) |
|
38 |
5674
|
39 if (nargin == 3) |
|
40 retval = strcmp (strtrunc (s1, n), strtrunc (s2, n)); |
|
41 else |
|
42 usage ("strncmp (s1, s2, n)"); |
5372
|
43 endif |
|
44 |
|
45 endfunction |