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. Advertisements

  2. Toby DiPasquale

    Matthew Moss Guest

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

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. Brian
    Replies:
    4
    Views:
    15,956
    abundantlife1010
    Jan 6, 2009
  2. Ike

    iterator to go backwards

    Ike, Jul 8, 2003, in forum: Java
    Replies:
    5
    Views:
    17,297
    Jason
    Jul 15, 2003
  3. Sharp

    Reading a string backwards

    Sharp, Mar 15, 2005, in forum: Java
    Replies:
    2
    Views:
    4,985
    Yamin
    Mar 15, 2005
  4. SK
    Replies:
    15
    Views:
    933
    Karl Heinz Buchegger
    Jun 17, 2004
  5. Peter Merz
    Replies:
    1
    Views:
    662
  6. Anand Pillai

    String search vs regexp search

    Anand Pillai, Oct 12, 2003, in forum: Python
    Replies:
    10
    Views:
    836
    Anand Pillai
    Oct 15, 2003
  7. Abby Lee
    Replies:
    5
    Views:
    713
    Abby Lee
    Aug 2, 2004
  8. mud_saisem

    Search a Large files backwards

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