annotate scripts/strings/strcmp.m @ 2275:38fea6d34daf

[project @ 1996-05-24 04:06:52 by jwe]
author jwe
date Fri, 24 May 1996 04:08:52 +0000
parents ea22c725914d
children 5cffc4b8de57
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1887
5d29638dd524 [project @ 1996-02-06 15:41:33 by jwe]
jwe
parents: 1315
diff changeset
1 # Copyright (C) 1996 John W. Eaton
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
2 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
3 # This file is part of Octave.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
4 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
5 # Octave is free software; you can redistribute it and/or modify it
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
6 # under the terms of the GNU General Public License as published by the
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
7 # Free Software Foundation; either version 2, or (at your option) any
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
8 # later version.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
9 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
10 # Octave is distributed in the hope that it will be useful, but WITHOUT
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
13 # for more details.
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
14 #
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
15 # You should have received a copy of the GNU General Public License
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
16 # along with Octave; see the file COPYING. If not, write to the Free
1315
611d403c7f3d [project @ 1995-06-25 19:56:32 by jwe]
jwe
parents: 1014
diff changeset
17 # Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
245
16a24e76d6e0 [project @ 1993-12-03 02:00:15 by jwe]
jwe
parents: 4
diff changeset
18
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
19 function status = strcmp (s1, s2)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
20
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
21 # usage: strcmp (s1, s2)
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
22 #
2265
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
23 # Compare two strings. Trailing blanks are significant.
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
24 #
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
25 # WARNING: Unlike the C function of the same name, this function
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
26 # returns 1 for equal and zero for not equal. Why? To be compatible
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
27 # with Matlab, of course.
2265
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
28 #
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
29 # Why doesn't this always return a scalar instead of vector with
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
30 # elements corresponding to the rows of the string array? To be
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
31 # compatible with Matlab, of course.
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
32
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
33 if (nargin != 2)
904
3470f1e25a79 [project @ 1994-11-09 21:22:15 by jwe]
jwe
parents: 321
diff changeset
34 usage ("strcmp (s, t)");
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
35 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
36
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
37 status = 0;
321
2d04965c32fb [project @ 1994-02-01 02:09:52 by jwe]
jwe
parents: 245
diff changeset
38 if (isstr (s1) && isstr(s2))
2265
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
39 c1 = columns (s1);
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
40 c2 = columns (s2);
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
41 if (c1 == c2)
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
42 if (c1 == 0)
321
2d04965c32fb [project @ 1994-02-01 02:09:52 by jwe]
jwe
parents: 245
diff changeset
43 status = 1;
2d04965c32fb [project @ 1994-02-01 02:09:52 by jwe]
jwe
parents: 245
diff changeset
44 else
2265
ea22c725914d [project @ 1996-05-23 20:17:52 by jwe]
jwe
parents: 2264
diff changeset
45 status = all (all (s1 == s2));
321
2d04965c32fb [project @ 1994-02-01 02:09:52 by jwe]
jwe
parents: 245
diff changeset
46 endif
2d04965c32fb [project @ 1994-02-01 02:09:52 by jwe]
jwe
parents: 245
diff changeset
47 endif
4
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
48 endif
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
49
b4df021f796c [project @ 1993-08-08 01:26:08 by jwe]
jwe
parents:
diff changeset
50 endfunction