find_first_not_of

提供:cppreference.com
移動: 案内, 検索

Syntax:

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

find_first_not_of()関数は、いずれかの動作をします。

  • 現在の文字列から"str"に含まれる文字にマッチしなかった最初の文字の位置を返します。検索開始位置を"index"で与えることができ、すべての文字がマッチする場合は、"string::npos"を返します。
  • 現在の文字列の"index"番目から"num"文字に対して、文字列"str"の文字を検索します。 最初にマッチしなかった位置を返し、すべての文字がマッチする場合は、"string::npos"を返します。
  • 文字'ch'が現在の文字列に対して、最初にマッチしなかった位置を返します。検索開始位置を"index"で与えることができ、すべての文字がマッチする場合は、"string::npos"を返します。

例えば、次のコードでは、"小文字とスペース、カンマ、ハイフン"以外の文字がテキストに含まれていないか検索します。

    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;

実行すると、find_first_not_of()が、大文字の文字を見つけ、29文字目にあることが出力されます。

    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

個人用ツール
名前空間
変種
操作
案内
ツールボックス
他の言語