std::basic_string_view<CharT,Traits>::find_first_not_of

出自cppreference.com
 
 
 
 
constexpr size_type
    find_first_not_of( basic_string_view v, size_type pos = 0 ) const noexcept;
(1) (C++17 起)
constexpr size_type
    find_first_not_of( CharT ch, size_type pos = 0 ) const noexcept;
(2) (C++17 起)
constexpr size_type
    find_first_not_of( const CharT* s, size_type pos, size_type count ) const;
(3) (C++17 起)
constexpr size_type
    find_first_not_of( const CharT* s, size_type pos = 0 ) const;
(4) (C++17 起)

尋找首個不等於給定字符序列中任何字符的字符。

1) 在此視圖中尋找首個不等於 v 中任意字符的字符,從位置 pos 開始。
2) 等價於 find_first_not_of(basic_string_view(std::addressof(c), 1), pos)
3) 等價於 find_first_not_of(basic_string_view(s, count), pos)
4) 等價於 find_first_not_of(basic_string_view(s), pos)

參數

v - 要搜索的視圖
pos - 要開始搜索的位置
count - 要比較的字符串的長度
s - 指向要比較的字符串的指針
ch - 要比較的字符

返回值

首個不等於給定字符串中任意字符的字符位置,或若找不到這些字符則為 std::string_view::npos

複雜度

最壞情況為 O(size() * v.size())。

示例

#include <string_view>
using namespace std::literals;

int main()
{
    static_assert(2 == "BCDEF"sv.find_first_not_of("ABC"));
                    //    ^
    static_assert(4 == "BCDEF"sv.find_first_not_of("ABC", 4));
                    //      ^
    static_assert(1 == "BCDEF"sv.find_first_not_of('B'));
                    //   ^
    static_assert(3 == "BCDEF"sv.find_first_not_of('D', 2));
                    //     ^
}

參閱

在視圖中查找字符
(公開成員函數) [編輯]
尋找子串的最後一次出現
(公開成員函數) [編輯]
查找字符的首次出現
(公開成員函數) [編輯]
查找字符的最後一次出現
(公開成員函數) [編輯]
查找字符的最後一次不出現
(公開成員函數) [編輯]
尋找字符的首次缺失
(std::basic_string<CharT,Traits,Allocator> 的公開成員函數) [編輯]