changelog shortlog tags changeset files revisions annotate raw

scripts/strings/rindex.m

changeset 10289: 4b124317dc38
parent:1bf0ce0930be
author: John W. Eaton <jwe@octave.org>
date: Tue Feb 09 20:58:55 2010 -0500 (26 minutes ago)
permissions: -rw-r--r--
description: base_properties::set_children: account for hidden children
1## Copyright (C) 1996, 1999, 2000, 2002, 2004, 2005, 2006, 2007, 2008, 2009
2## Kurt Hornik
3##
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
8## the Free Software Foundation; either version 3 of the License, or (at
9## your option) any later version.
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
17## along with Octave; see the file COPYING. If not, see
18## <http://www.gnu.org/licenses/>.
19
20## -*- texinfo -*-
21## @deftypefn {Function File} {} rindex (@var{s}, @var{t})
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,
25##
26## @example
27## @group
28## rindex ("Teststring", "t")
29## @result{} 6
30## @end group
31## @end example
32##
33## @strong{Caution:} This function does not work for arrays of
34## character strings.
35## @seealso{find, index}
36## @end deftypefn
37
38## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
39## Adapted-By: jwe
40
41function n = rindex (s, t)
42
43 ## This is patterned after the AWK function of the same name.
44
45 if (nargin != 2)
46 print_usage ();
47 endif
48
49 n = index (s, t, "last");
50
51endfunction
52
53%!assert(rindex ("foobarbaz", "b") == 7 && rindex ("foobarbaz", "o") == 3);
54
55%!error rindex ();
56
57%!error rindex ("foo", "bar", 3);
58