zoukankan      html  css  js  c++  java
  • std::string::find_last_not_of

    public member function
    <string>

    std::string::find_last_not_of

    string (1)
    size_t find_last_not_of (const string& str, size_t pos = npos) const;
    
    c-string (2)
    size_t find_last_not_of (const char* s, size_t pos = npos) const;
    
    buffer (3)
    size_t find_last_not_of (const char* s, size_t pos, size_t n) const;
    
    character (4)
    size_t find_last_not_of (char c, size_t pos = npos) const;
    
    Find non-matching character in string from the end
    Searches the string for the last character that does not match any of the characters specified in its arguments.

    When pos is specified, the search only includes characters at or before position pos, ignoring any possible occurrences after pos.

    Parameters

    str
    Another string with the set of characters to be used in the search.
    pos
    Position of the last character in the string to be considered in the search.
    Any value greater than, or equal to, the string length (including string::npos) means that the entire string is searched.
    Note: The first character is denoted by a value of 0 (not 1).
    s
    Pointer to an array of characters.
    If argument n is specified (3), the first n characters in the array are used in the search.
    Otherwise (2), a null-terminated sequence is expected: the length of the sequence with the characters used in the search is determined by the first occurrence of a null character.
    n
    Number of character values to search for.
    c
    Individual character to be searched for.

    size_t is an unsigned integral type (the same as member typestring::size_type).

    Return Value

    The position of the first character that does not match.
    If no such characters are found, the function returns string::npos.

    size_t is an unsigned integral type (the same as member typestring::size_type).

    Example

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    // string::find_last_not_of
    #include <iostream>       // std::cout
    #include <string>         // std::string
    #include <cstddef>        // std::size_t
    
    int main ()
    {
      std::string str ("Please, erase trailing white-spaces   
    ");
      std::string whitespaces (" 	fv
    
    ");
    
      std::size_t found = str.find_last_not_of(whitespaces);
      if (found!=std::string::npos)
        str.erase(found+1);
      else
        str.clear();            // str is all whitespace
    
      std::cout << '[' << str << "]
    ";
    
      return 0;
    }


    [Please, erase trailing white-spaces]
    

    Complexity

    Unspecified, but generally up to linear in the string length (or pos) times the number of characters to match (worst case).

    Iterator validity

    No changes.

    Data races

    The object is accessed.

    Exception safety

    If s does not point to an array long enough, it causes undefined behavior.
    Otherwise, the function never throws exceptions (no-throw guarantee).

    See also

  • 相关阅读:
    Linux内核学习第五周 系统调用
    Linux内核学习第三周 Linux启动过程分析
    WebStorm快捷键大全
    PAT乙级-1056. 组合数的和(15)
    PAT乙级-1043. 输出PATest(20)
    PAT乙级-1021.个位数统计(15)
    PAT乙级-1036.跟奥巴马一起编程(15)
    学习笔记-C++ STL iterator与对指针的理解-20170618
    学习笔记-Little Tips_day20170615-" " and ' '
    HTML5离线存储和本地缓存
  • 原文地址:https://www.cnblogs.com/catgatp/p/6407817.html
Copyright © 2011-2022 走看看