std::basic_string_view<CharT,Traits>::contains
出自cppreference.com
< cpp | string | basic string view
constexpr bool contains( basic_string_view sv ) const noexcept; |
(1) | (C++23 起) |
constexpr bool contains( CharT c ) const noexcept; |
(2) | (C++23 起) |
constexpr bool contains( const CharT* s ) const; |
(3) | (C++23 起) |
檢查字元串視圖是否含有給定的子串,其中
1) 子串為字元串視圖。
2) 子串為單個字元。
3) 字串為空終止字元串。
所有三個重載都等價於 return find(x) != npos;,其中 x
為形參。
目錄 |
[編輯] 參數
sv | - | 字元串視圖 |
c | - | 單個字元 |
s | - | 空終止字元串 |
[編輯] 返回值
若字元串視圖含有給定的子串則為 true,否則為 false。
[編輯] 註解
功能特性測試宏 | 值 | 標準 | 功能特性 |
---|---|---|---|
__cpp_lib_string_contains |
202011L |
(C++23) | contains 函數
|
[編輯] 示例
運行此代碼
#include <string_view> using namespace std::literals; static_assert ( // bool contains(basic_string_view x) const noexcept; "https://cppreference.com"sv.contains("cpp"sv) == true and "https://cppreference.com"sv.contains("php"sv) == false and // bool contains(CharT x) const noexcept; "C++23"sv.contains('+') == true and "C++23"sv.contains('-') == false and // bool contains(const CharT* x) const; std::string_view("basic_string_view").contains("string") == true and std::string_view("basic_string_view").contains("String") == false ); int main() {}
[編輯] 參閱
(C++20) |
檢查字元串視圖是否始於給定前綴 (公開成員函數) |
(C++20) |
檢查字元串視圖是否終於給定後綴 (公開成員函數) |
在視圖中查找字元 (公開成員函數) | |
返回子串 (公開成員函數) | |
(C++23) |
檢查字元串是否含有給定的子串或字元 ( std::basic_string<CharT,Traits,Allocator> 的公開成員函數)
|