annotate scripts/strings/substr.m @ 2311:2b5788792cad

[project @ 1996-07-11 20:18:38 by jwe]
author jwe
date Thu, 11 Jul 1996 20:18:38 +0000
parents 5cffc4b8de57
children 5ca126254d15
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
1 ### Copyright (C) 1996 Kurt Hornik
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
2 ###
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
3 ### This file is part of Octave.
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
4 ###
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
5 ### Octave is free software; you can redistribute it and/or modify it
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
6 ### under the terms of the GNU General Public License as published by
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
7 ### the Free Software Foundation; either version 2, or (at your option)
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
8 ### any later version.
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
9 ###
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
10 ### Octave is distributed in the hope that it will be useful, but
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
11 ### WITHOUT ANY WARRANTY; without even the implied warranty of
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
12 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
13 ### General Public License for more details.
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
14 ###
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
15 ### You should have received a copy of the GNU General Public License
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
16 ### along with Octave; see the file COPYING. If not, write to the Free
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
17 ### Software Foundation, 59 Temple Place - Suite 330, Boston, MA
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
18 ### 02111-1307, USA.
2270
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
19
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
20 ## usage: substr (s, beg, len)
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
21 ##
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
22 ## Returns the substring of S of length LEN starting at index BEG.
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
23 ## If LEN is missing, the substring extends to the end of S.
2270
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
24
2311
2b5788792cad [project @ 1996-07-11 20:18:38 by jwe]
jwe
parents: 2303
diff changeset
25 function t = substr (s, beg, len)
2270
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
26
2303
5cffc4b8de57 [project @ 1996-06-24 09:15:24 by jwe]
jwe
parents: 2276
diff changeset
27 ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>.
2270
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
28
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
29 if (nargin < 2 || nargin > 3)
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
30 usage ("substr (s, beg, len)");
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
31 endif
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
32
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
33 if (isstr (s))
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
34 nc = columns (s);
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
35 if (beg > 0 && beg <= nc)
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
36 if (nargin == 2)
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
37 eos = nc;
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
38 else
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
39 eos = beg + len - 1;
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
40 endif
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
41 if (eos <= nc)
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
42 t = s (:, beg:eos);
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
43 else
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
44 error ("substr: length = %d out of range", len);
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
45 endif
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
46 else
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
47 error ("substr: beginning index = %d out of range", beg);
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
48 endif
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
49 else
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
50 error ("substr: expecting string argument");
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
51 endif
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
52
cfcf8ff7d2dd [project @ 1996-05-24 02:10:11 by jwe]
jwe
parents:
diff changeset
53 endfunction