1 ## Copyright (C) 1996-2012 Kurt Hornik
3 ## This file is part of Octave.
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 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} rindex (@var{s}, @var{t})
21 ## Return the position of the last occurrence of the character string
22 ## @var{t} in the character string @var{s}, or 0 if no occurrence is
23 ## found. @var{s} may also be a string array or cell array of strings.
29 ## rindex ("Teststring", "t")
34 ## The @code{rindex} function is equivalent to @code{index} with
35 ## @var{direction} set to @samp{"last"}.
37 ## @seealso{find, index}
40 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
42 ## This is patterned after the AWK function of the same name.
44 function n = rindex (s, t)
50 n = index (s, t, "last");
55 %!assert(rindex ("foobarbaz", "b") == 7 && rindex ("foobarbaz", "o") == 3);
58 %! str = char ("Hello", "World", "Goodbye", "World");
59 %! assert (rindex (str, "o"), [5; 2; 3; 2]);
60 %! str = cellstr (str);
61 %! assert (rindex (str, "o"), [5; 2; 3; 2]);
63 %% Test input validation
65 %!error rindex ("foo")
66 %!error rindex ("foo", "bar", "last")