std::string::find_first_not_of
<string>
size_t find_first_not_of ( const string& str, size_t pos = 0 ) const;
size_t find_first_not_of ( const char* s, size_t pos, size_t n ) const;
size_t find_first_not_of ( const char* s, size_t pos = 0 ) const;
size_t find_first_not_of ( char c, size_t pos = 0 ) const;
Find absence of character in string
Searches for the first 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 after position
pos, ignoring any content in the previous character positions.
Parameters
- str
- string containing the characters to match against in the object.
- s
- Array with a sequence of characters. The position of first character in the string that does not compare equal to any of the characters in this sequence is returned.
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 first character in the object that is not c.
- pos
- Position of the first character in the string to be taken into consideration for matches. A value of 0 means that the entire string is considered.
Return Value
The position of the first 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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
// string::find_first_not_of
#include <iostream>
#include <string>
using namespace std;
int main ()
{
string str ("look for non-alphabetic characters...");
size_t found;
found=str.find_first_not_of("abcdefghijklmnopqrstuvwxyz ");
if (found!=string::npos)
{
cout << "First non-alphabetic character is " << str[found];
cout << " at position " << int(found) << endl;
}
return 0;
}
|
First non-alphabetic character is - at position 12 |
Basic template member declarations
( basic_string<charT,traits,Allocator> )
1 2 3 4 5 6 7 8
|
typedef typename Allocator::size_type size_type;
size_type find_first_not_of ( const basic_string& str,
size_type pos = 0 ) const;
size_type find_first_not_of ( const charT* s, size_type pos,
size_type n ) const;
size_type find_first_not_of ( const charT* s,
size_type pos = 0 ) const;
size_type find_first_not_of ( charT c, size_type pos = 0 ) const;
|
See also
- string::find
- Find content in string (public member function)
- string::find_first_of
- Find character in string (public member function)
- string::find_last_not_of
- Find absence of character in string from the end (public member function)
- string::replace
- Replace part of string (public member function)
- string::substr
- Generate substring (public member function)