find_first_not_of [C++ Reference]
Keywords: string,find_first_not_of
Date: 2009-10-08T21:38:26-0700

[[find_first_not_of]]
C++ Reference
Translations of this page?:

- en
- br-pt
- cn
- fr
- it
- jp
- pl
- ru
- tr

## find_first_not_of

Syntax:

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

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,
- searches 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 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

Related Topics: find, find_first_not_of, find_first_of, find_last_not_of, find_last_of, rfind

Edit this page • Old revisions
• • • Login • Index • Recent changes • RSS • cc •