The differences between string::rfind() and string::find_last_of()

This is a discussion on The differences between string::rfind() and string::find_last_of() within the C++ Programming forums, part of the General Programming Boards category; The difference between string::rfind() and string::find_last_of() is: str.rfind("abc") finds the complete substring "abc" in reverse order str.find_last_of("abc") finds any character ...

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    284

    The differences between string::rfind() and string::find_last_of()

    The difference between string::rfind() and string::find_last_of() is:
    str.rfind("abc") finds the complete substring "abc" in reverse order
    str.find_last_of("abc") finds any character of a/b/c from the end of str.
    Is my understanding correct?

  2. #2
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by meili100 View Post
    str.rfind("abc") finds the complete substring "abc" in reverse order
    Well that would certainly be confusing...
    You could always try it and find out, but that's not the way I read it here:
    http://www.cppreference.com/cppstring/rfind.html

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    If str is "abcabc", then rfind("abc") will return 3 and find_last_of("abc") will return 5. The difference between the two that I think you understand correctly is that find_last_of searches for any one of the characters provided, whereas rfind searches for the entire string provided.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21