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,
  • does a reverse search in the current string, beginning at index, for any character that does not match the first num characters in str, returning the index in the current string of the first character found that meets this criteria, otherwise returning string::npos,
  • 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