cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : Strings library : string : find_last_not_of
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
Strings library
char_traits
classes:
· string
global functions:
· getline
· operator+
· operator<<
· operator>>
· comparison operators
· swap
string
· string::string
member constants:
· string::npos
member functions:
· string::append
· string::assign
· string::at
· string::begin
· string::capacity
· string::clear
· string::compare
· string::copy
· string::c_str
· string::data
· string::empty
· string::end
· string::erase
· string::find
· string::find_first_not_of
· string::find_first_of
· string::find_last_not_of
· string::find_last_of
· string::get_allocator
· string::insert
· string::length
· string::max_size
· string::operator+=
· string::operator=
· string::operator[]
· string::push_back
· string::rbegin
· string::rend
· string::replace
· string::reserve
· string::resize
· string::rfind
· string::size
· string::substr
· string::swap

-

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)
string::find_last_of Find character in string from the end (public member function)
string::find_first_not_of Find absence of character in string
string::replace Replace part of string (public member function)
string::substr Generate substring (public member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us