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

The find_first_not_of() function either:

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

For example, the following code searches a string of text for the first character that is not a lower-case character, space, comma, or hypen:

 string lower_case = "abcdefghijklmnopqrstuvwxyz ,-";
 string str = "this is the lower-case part, AND THIS IS THE UPPER-CASE PART";
 cout << "first non-lower-case letter in str at: " << str.find_first_not_of(lower_case) << endl;            

When run, find_first_not_of() finds the first upper-case letter in str at index 29 and displays this output:

 first non-lower-case letter in str at: 29