6139
|
1 ## Copyright (C) 1996, 2006 Kurt Hornik |
2325
|
2 ## |
2313
|
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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## any later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but |
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
13 ## General Public License 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 |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
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 |