std::basic_string_view<CharT,Traits>::contains
出自cppreference.com
| |
(1) | (C++23 起) |
| |
(2) | (C++23 起) |
| |
(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> 的公開成員函數)
|