String search backwards?

Discussion in 'Ruby' started by Toby DiPasquale, Jan 24, 2006.

  1. Hi all,

    Can Ruby search a string backwards? I can't find any reference to this
    in the docs or online, but it seems as if you should be able to do this.

    What I would like, ideally, is a method like:

    n = rstrstr( orig_str, sub_str)

    where n is the starting index of the last occurrence of sub_str in
    orig_str. Anybody know how to do this? I tried using the 'r' modifier to
    // but that failed as well.

    --
    Posted via http://www.ruby-forum.com/.
     
    Toby DiPasquale, Jan 24, 2006
    #1
    1. Advertising

  2. Toby DiPasquale

    Matthew Moss Guest

    n =3D orig_str.rindex(sub_str)
     
    Matthew Moss, Jan 24, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sharp

    Reading a string backwards

    Sharp, Mar 15, 2005, in forum: Java
    Replies:
    2
    Views:
    4,830
    Yamin
    Mar 15, 2005
  2. SK
    Replies:
    15
    Views:
    798
    Karl Heinz Buchegger
    Jun 17, 2004
  3. Peter Merz
    Replies:
    1
    Views:
    587
  4. Abby Lee
    Replies:
    5
    Views:
    443
    Abby Lee
    Aug 2, 2004
  5. mud_saisem

    Search a Large files backwards

    mud_saisem, Mar 2, 2010, in forum: Perl Misc
    Replies:
    7
    Views:
    154
    Uri Guttman
    Mar 2, 2010
Loading...

Share This Page