search backward

Discussion in 'Python' started by Robert, Jan 4, 2005.

  1. Robert

    Robert Guest

    I need to find the location of a short string in a long string. The
    problem however is that i need to search backward.

    Does anybody know how to search in reverse direction?


    Thanks,
    Robert
     
    Robert, Jan 4, 2005
    #1
    1. Advertising

  2. Robert wrote:
    > I need to find the location of a short string in a long string. The
    > problem however is that i need to search backward.
    >
    > Does anybody know how to search in reverse direction?


    >>> "foofoo".find("foo")

    0
    >>> "foofoo".rfind("foo")

    3
    >>> "foofoo".index("foo")

    0
    >>> "foofoo".rindex("foo")

    3

    --
    --------------------------------------------------------------------
    Aaron Bingham
    Application Developer
    Cenix BioScience GmbH
    --------------------------------------------------------------------
     
    Aaron Bingham, Jan 4, 2005
    #2
    1. Advertising

  3. Robert wrote:
    > I need to find the location of a short string in a long string. The
    > problem however is that i need to search backward.
    >
    > Does anybody know how to search in reverse direction?


    How about str.rfind?

    py> s = 'abc:def:abc'
    py> s.rfind('abc')
    8

    Steve
     
    Steven Bethard, Jan 4, 2005
    #3
    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. paul
    Replies:
    6
    Views:
    384
  2. =?Utf-8?B?TUxpYmJ5?=

    Netscape - Backward compatibility testing

    =?Utf-8?B?TUxpYmJ5?=, Sep 4, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    648
    [MSFT]
    Sep 6, 2004
  3. Mick

    Simulate the IE backward button

    Mick, Dec 15, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    401
  4. Steve C. Orr [MVP, MCSD]

    Re: disable backward navigation of the browser

    Steve C. Orr [MVP, MCSD], Mar 7, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,483
    Jeffrey Palermo
    Mar 7, 2005
  5. Abby Lee
    Replies:
    5
    Views:
    483
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page