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

出自cppreference.com
Lynnboy留言 | 貢獻2024年3月9日 (六) 10:43的修訂
(差異) ←上個修訂 | 最新修訂 (差異) | 下個修訂→ (差異)
 
 
 
 
constexpr size_type
    find_last_not_of( basic_string_view v, size_type pos = npos ) const noexcept;
(1) (C++17 起)
constexpr size_type
    find_last_not_of( CharT ch, size_type pos = npos ) const noexcept;
(2) (C++17 起)
constexpr size_type
    find_last_not_of( const CharT* s, size_type pos, size_type count ) const;
(3) (C++17 起)
constexpr size_type
    find_last_not_of( const CharT* s, size_type pos = npos ) const;
(4) (C++17 起)

尋找不等於給定字符序列的任意字符的最後一個字符。

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

參數

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

返回值

最後一個不等於給定字符串中任意字符的字符位置,或若找不到這些字符則為 npos

複雜度

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

示例

#include <string_view>
using std::operator""sv;

int main()
{
    static_assert(1 == "BCDEF"sv.find_last_not_of("DEF"));
                    //   ^
    static_assert(2 == "BCDEFG"sv.find_last_not_of("EFG", 3));
                    //    ^
    static_assert(2 == "ABBA"sv.find_last_not_of('A'));
                    //    ^
    static_assert(1 == "ABBA"sv.find_last_not_of('A', 1));
                    //   ^
}

參閱

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