find_last_not_of [C++ Reference]
Keywords: string,find_last_not_of
Date: 2010-03-11T02:04:46-0800

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

- en
- br-pt
- cn
- cz
- de
- es
- fr
- it
- jp
- nl
- pl
- ro
- ru
- sk
- tr
- tw

## find_last_not_of

Syntax:

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

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 of the first num characters 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 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

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

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