7017
|
1 ## Copyright (C) 1996, 1999, 2000, 2002, 2004, 2005, 2006, 2007 |
|
2 ## Kurt Hornik |
2325
|
3 ## |
2313
|
4 ## This file is part of Octave. |
|
5 ## |
|
6 ## Octave is free software; you can redistribute it and/or modify it |
|
7 ## under the terms of the GNU General Public License as published by |
7016
|
8 ## the Free Software Foundation; either version 3 of the License, or (at |
|
9 ## your option) any later version. |
2313
|
10 ## |
|
11 ## Octave is distributed in the hope that it will be useful, but |
|
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
14 ## General Public License for more details. |
|
15 ## |
|
16 ## You should have received a copy of the GNU General Public License |
7016
|
17 ## along with Octave; see the file COPYING. If not, see |
|
18 ## <http://www.gnu.org/licenses/>. |
2271
|
19 |
3361
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} rindex (@var{s}, @var{t}) |
6139
|
22 ## Return the position of the last occurrence of the character string |
|
23 ## @var{t} in the character string @var{s}, or 0 if no occurrence is |
|
24 ## found. For example, |
3426
|
25 ## |
3361
|
26 ## @example |
|
27 ## rindex ("Teststring", "t") |
|
28 ## @result{} 6 |
|
29 ## @end example |
3426
|
30 ## |
6139
|
31 ## @strong{Caution:} This function does not work for arrays of |
|
32 ## character strings. |
|
33 ## @seealso{find, index} |
3361
|
34 ## @end deftypefn |
2271
|
35 |
5428
|
36 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
2355
|
37 ## Adapted-By: jwe |
2314
|
38 |
2311
|
39 function n = rindex (s, t) |
2271
|
40 |
2303
|
41 ## This is patterned after the AWK function of the same name. |
2271
|
42 |
|
43 if (nargin != 2) |
6046
|
44 print_usage (); |
2271
|
45 endif |
|
46 |
6139
|
47 n = index (s, t, "last"); |
3911
|
48 |
2271
|
49 endfunction |