std::string_view find_last_not_of() 方法
- 自 C++17 起
// (1) Const version only
constexpr size_type find_last_not_of( const basic_string& str, size_type pos = 0 ) const noexcept;
// (2) Const version only
constexpr size_type find_last_not_of( const CharT* s, size_type pos, size_type count ) const;
// (3) Const version only
constexpr size_type find_last_not_of( const CharT* s, size_type pos = 0 ) const;
// (4) Const version only
constexpr size_type find_last_not_of( CharT ch, size_type pos = 0 ) const noexcept;
查找不等于给定字符序列中任何字符的最后一个字符。
搜索仅考虑区间 **[ 0, pos ]**。
- (1) 在此视图中,从位置
pos
开始,查找不等于v
中任何字符的最后一个字符。 - (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));
// ^
}