std::basic_string_view<CharT,Traits>::rfind
来自 cppreference.cn
< cpp | string | basic string view
constexpr size_type rfind( basic_string_view v, size_type pos = npos ) const noexcept; |
(1) | (since C++17) |
constexpr size_type rfind( CharT ch, size_type pos = npos ) const noexcept; |
(2) | (since C++17) |
constexpr size_type rfind( const CharT* s, size_type pos, size_type count ) const; |
(3) | (since C++17) |
constexpr size_type rfind( const CharT* s, size_type pos = npos ) const; |
(4) | (since C++17) |
查找与给定字符序列相等的最后子字符串。搜索从 pos 开始,并从右向左进行(因此,如果找到子字符串,则它不能在 pos 之后的某个位置开始)。如果 npos 或任何不小于 size() - 1 的值作为 pos 传递,则将搜索整个字符串。
1) 在此视图中查找 v 的最后一次出现,从位置 pos 开始。
2) 等效于 rfind(basic_string_view(std::addressof(ch), 1), pos)。
3) 等效于 rfind(basic_string_view(s, count), pos)。
4) 等效于 rfind(basic_string_view(s), pos)。
目录 |
[编辑] 参数
v | - | 要搜索的视图 |
pos | - | 开始搜索的位置 |
count | - | 要搜索的子字符串的长度 |
s | - | 指向要搜索的字符串的指针 |
ch | - | 要搜索的字符 |
[编辑] 返回值
找到的子字符串的第一个字符的位置,如果未找到此类子字符串,则为 npos。
[编辑] 复杂度
[编辑] 示例
运行此代码
#include <string_view> int main() { using namespace std::literals; constexpr auto N = std::string_view::npos; static_assert(true && (6 == "AB AB AB"sv.rfind("AB")) && (6 == "AB AB AB"sv.rfind("ABCD", N, 2)) && (3 == "AB AB AB"sv.rfind("AB", 5)) && (0 == "AB CD EF"sv.rfind("AB", 0)) && (2 == "B AB AB "sv.rfind("AB", 2)) && (N == "B AB AB "sv.rfind("AB", 1)) && (5 == "B AB AB "sv.rfind('A')) && (4 == "AB AB AB"sv.rfind('B', 4)) && (N == "AB AB AB"sv.rfind('C')) ); }
[编辑] 参见
在视图中查找字符 (public member function) | |
查找字符首次出现的位置 (public member function) | |
查找字符最后一次出现的位置 (public member function) | |
查找字符首次缺失的位置 (public member function) | |
查找字符最后一次缺失的位置 (public member function) | |
查找子字符串的最后一次出现 (public member function of std::basic_string<CharT,Traits,Allocator> ) |