名稱空間
變體
操作

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

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

查詢與給定字元序列中某個字元相等的最後一個字元。未指定確切的搜尋演算法。搜尋僅考慮區間 [0pos]。如果該字元不在區間中,則返回 npos

1) 查詢此檢視中 v 的任何字元在位置 pos 結束的最後一次出現。
2) 等價於 find_last_of(basic_string_view(std::addressof(ch), 1), pos)
3) 等價於 find_last_of(basic_string_view(s, count), pos)
4) 等價於 find_last_of(basic_string_view(s), pos)

目錄

[編輯] 引數

v - 要搜尋的檢視
pos - 搜尋結束的位置
count - 要搜尋的字元字串的長度
s - 指向要搜尋的字元字串的指標
ch - 要搜尋的字元

[編輯] 返回值

子字串中任何字元最後一次出現的位置,如果未找到此類字元,則為 npos

[編輯] 複雜度

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

[編輯] 示例

#include <string_view>
 
using namespace std::literals;
constexpr auto N = std::string_view::npos;
 
static_assert(
    5 == "delete"sv.find_last_of("cdef"sv) &&
      //       └────────────────────┘
    N == "double"sv.find_last_of("fghi"sv) &&
      //
    0 == "else"sv.find_last_of("bcde"sv, 2 /* pos [0..2]: "els" */) &&
      //  └────────────────────────┘
    N == "explicit"sv.find_last_of("abcd"sv, 4 /* pos [0..4]: "expli" */) &&
      //
    3 == "extern"sv.find_last_of('e') &&
      //     └────────────────────┘
    N == "false"sv.find_last_of('x') &&
      //
    0 == "inline"sv.find_last_of('i', 2 /* pos [0..2]: "inl" */) &&
      //  └───────────────────────┘
    N == "mutable"sv.find_last_of('a', 2 /* pos [0..2]: "mut" */) &&
      //
    3 == "namespace"sv.find_last_of("cdef", 3 /* pos [0..3]: "name" */, 3 /* "cde" */) &&
      //     └─────────────────────────┘
    N == "namespace"sv.find_last_of("cdef", 3 /* pos [0..3]: "name" */, 2 /* "cd" */)
);
 
int main() {}

[編輯] 參閱

在檢視中查詢字元
(公共成員函式) [編輯]
查詢子串的最後一次出現
(公共成員函式) [編輯]
查詢字元的首次出現
(公共成員函式) [編輯]
查詢字元的首次缺席
(公共成員函式) [編輯]
查詢字元的最後一次缺席
(公共成員函式) [編輯]
查詢字元的最後一次出現
(std::basic_string<CharT,Traits,Allocator> 的公共成員函式) [編輯]