Mercurial > hg > octave-lyh
comparison scripts/strings/substr.m @ 2270:cfcf8ff7d2dd
[project @ 1996-05-24 02:10:11 by jwe]
Initial revision
author | jwe |
---|---|
date | Fri, 24 May 1996 02:10:11 +0000 |
parents | |
children | 6dedd4e0a82f |
comparison
equal
deleted
inserted
replaced
2269:517a43164a60 | 2270:cfcf8ff7d2dd |
---|---|
1 # Copyright (C) 1996 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 the | |
7 # Free Software Foundation; either version 2, or (at your option) any | |
8 # later version. | |
9 # | |
10 # Octave is distributed in the hope that it will be useful, but WITHOUT | |
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
13 # 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
18 | |
19 function t = substr (s, beg, len) | |
20 | |
21 # usage: substr (s, beg, len) | |
22 # | |
23 # Returns the substring of S of length LEN starting at index BEG. | |
24 # If LEN is missing, the substring extends to the end of S. | |
25 | |
26 # Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>. | |
27 | |
28 if (nargin < 2 || nargin > 3) | |
29 usage ("substr (s, beg, len)"); | |
30 endif | |
31 | |
32 if (isstr (s)) | |
33 nc = columns (s); | |
34 if (beg > 0 && beg <= nc) | |
35 if (nargin == 2) | |
36 eos = nc; | |
37 else | |
38 eos = beg + len - 1; | |
39 endif | |
40 if (eos <= nc) | |
41 t = s (:, beg:eos); | |
42 else | |
43 error ("substr: length = %d out of range", len); | |
44 endif | |
45 else | |
46 error ("substr: beginning index = %d out of range", beg); | |
47 endif | |
48 else | |
49 error ("substr: expecting string argument"); | |
50 endif | |
51 | |
52 endfunction |