Mercurial > hg > octave-lyh
comparison scripts/strings/split.m @ 2325:b5568c31ee2c
[project @ 1996-07-15 22:20:21 by jwe]
author | jwe |
---|---|
date | Mon, 15 Jul 1996 22:20:21 +0000 |
parents | 949ab8eba8bc |
children | c9f70d39255f |
comparison
equal
deleted
inserted
replaced
2324:fdc6e2f81333 | 2325:b5568c31ee2c |
---|---|
1 ## Copyright (C) 1996 Kurt Hornik | 1 ## Copyright (C) 1996 Kurt Hornik |
2 ## | 2 ## |
3 ## This file is part of Octave. | 3 ## This file is part of Octave. |
4 ## | 4 ## |
5 ## Octave is free software; you can redistribute it and/or modify it | 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 | 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) | 7 ## the Free Software Foundation; either version 2, or (at your option) |
24 ## matrix). | 24 ## matrix). |
25 | 25 |
26 ## Author: jwe | 26 ## Author: jwe |
27 | 27 |
28 function m = split (s, t) | 28 function m = split (s, t) |
29 | 29 |
30 ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>. | 30 ## Original version by Kurt Hornik <Kurt.Hornik@ci.tuwien.ac.at>. |
31 | 31 |
32 if (nargin != 2) | 32 if (nargin != 2) |
33 usage ("split (s, t)"); | 33 usage ("split (s, t)"); |
34 endif | 34 endif |
35 | 35 |
36 if (isstr (s) && isstr (t)) | 36 if (isstr (s) && isstr (t)) |
37 | 37 |
38 l_s = length (s); | 38 l_s = length (s); |
39 l_t = length (t); | 39 l_t = length (t); |
40 | 40 |
41 if (l_s < l_t) | 41 if (l_s < l_t) |
42 error ("split: s must not be shorter than t"); | 42 error ("split: s must not be shorter than t"); |
43 endif | 43 endif |
44 | 44 |
45 if (l_t == 0) | 45 if (l_t == 0) |
46 ind = 1 : (l_s + 1); | 46 ind = 1 : (l_s + 1); |
47 else | 47 else |
48 ind = findstr (s, t, 0); | 48 ind = findstr (s, t, 0); |
49 if (length (ind) == 0) | 49 if (length (ind) == 0) |
68 endif | 68 endif |
69 | 69 |
70 endfor | 70 endfor |
71 | 71 |
72 m = eval (sprintf ("str2mat (%s);", cmd)); | 72 m = eval (sprintf ("str2mat (%s);", cmd)); |
73 | 73 |
74 | 74 |
75 else | 75 else |
76 error ("split: both s and t must be strings"); | 76 error ("split: both s and t must be strings"); |
77 endif | 77 endif |
78 | 78 |