find_last_not_of
Syntax:
  #include <string>
  size_type find_last_not_of( const string& str, size_type index = npos );
  size_type find_last_not_of( const char* str, size_type index = npos);
  size_type find_last_not_of( const char* str, size_type index, size_type num );
  size_type find_last_not_of( char ch, size_type index = npos );

The find_last_not_of() function either:

  • returns the index of the last character within the current string that does not match any character in str, doing a reverse search from index, string::npos if nothing is found,
  • returns the index of the last character within the current string that does not match any character in str, doing a reverse search from index and searching at most num characters of str, or returning string::npos if nothing is found,
  • or returns the index of the last occurrence of a character that does not match ch in the current string, doing a reverse search from index, string::npos if nothing is found.

For example, the following code searches for the last non-lower-case character in a mixed string of characters:

 string lower_case = "abcdefghijklmnopqrstuvwxyz";
 string str = "abcdefgABCDEFGhijklmnop";
 cout << "last non-lower-case letter in str at: " << str.find_last_not_of(lower_case) << endl;              

This code displays the following output:

 last non-lower-case letter in str at: 13