string::find_last_not_of |
public member function |
size_t find_last_not_of ( const string& str, size_t pos = npos ) const;
size_t find_last_not_of ( const char* s, size_t pos, size_t n ) const;
size_t find_last_not_of ( const char* s, size_t pos = npos ) const;
size_t find_last_not_of ( char c, size_t pos = npos ) const; |
|
Find absence of character in string from the end
Searches for the last character in the object which is not part of either str, s or c, and returns its position.
When pos is specified the search only includes characters on or before position pos, ignoring any content in the character positions after it.
Parameters
- str
- string containing the characters to match against in the object.
- s
- Array with a sequence of characters.
In the second member function version, the number of characters in the sequence of characters to match against is only determined by parameter n.
In the third version, a null-terminated sequence (c-string) is expected, and the amount of characters to match against is determined by its length, which is indicated by a null-character after the last character.
- n
- Length of the sequence of characters s.
- c
- Individual character. The function returns the position of the last character in the object that is not c.
- pos
- Position of the last character in the string to be taken into consideration for matches. The default value npos indicates that the entire string is considered.
Return Value
The position of the last character in the object that is not part of characters it is being matched against.
If no such position is found, the member value
npos is returned.
Example
// string::find_last_not_of
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("erase trailing white-spaces \n");
string whitespaces (" \t\f\v\n\r");
size_t found;
found=str.find_last_not_of(whitespaces);
if (found!=string::npos)
str.erase(found+1);
else
str.clear(); // str is all whitespace
cout << '"' << str << '"' << endl;
return 0;
}
|
"erase trailing white-spaces" |
Basic template member declarations
( basic_string<charT,traits,Allocator> )
typedef typename Allocator::size_type size_type;
size_type find_last_not_of ( const basic_string& str,
size_type pos = npos ) const;
size_type find_last_not_of ( const charT* s, size_type pos,
size_type n ) const;
size_type find_last_not_of ( const charT* s,
size_type pos = npos ) const;
size_type find_last_not_of ( charT c, size_type pos = npos ) const;
|
See also
string::find | Find content in string (public member function) |
string::rfind | Find last occurrence of content in string (public member function) |