Index counting from the last char

Discussion in 'Python' started by gisleyt, May 22, 2006.

  1. gisleyt

    gisleyt Guest

    I'd like to use the index-function to retrieve a certain char in a
    string, but i need it to start counting from the last char.

    E.g. in the string.

    Foo-bar, foo foo-bar

    I want the latter hyphen to be returned when i do a index for '-'. Is
    there any built in function for this, I don't want to reverse every
    string just to do this.

    -Gisle-
    gisleyt, May 22, 2006
    #1
    1. Advertising

  2. gisleyt

    Duncan Booth Guest

    gisleyt wrote:

    > I'd like to use the index-function to retrieve a certain char in a
    > string, but i need it to start counting from the last char.
    >
    > E.g. in the string.
    >
    > Foo-bar, foo foo-bar
    >
    > I want the latter hyphen to be returned when i do a index for '-'. Is
    > there any built in function for this, I don't want to reverse every
    > string just to do this.
    >

    str.rindex
    Duncan Booth, May 22, 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. lovecreatesbeauty
    Replies:
    1
    Views:
    1,015
    Ian Collins
    May 9, 2006
  2. gert
    Replies:
    20
    Views:
    1,144
  3. Shawn W_
    Replies:
    5
    Views:
    264
    Aldric Giacomoni
    Sep 16, 2009
  4. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    270
    Tomasz Chmielewski
    Mar 4, 2008
  5. edwardfredriks

    counting up instead of counting down

    edwardfredriks, Sep 6, 2005, in forum: Javascript
    Replies:
    6
    Views:
    188
    Dr John Stockton
    Sep 7, 2005
Loading...

Share This Page