std::basic_string_view<CharT,Traits>::contains - cppreference.com

From cppreference.com

constexprboolcontains(basic_string_viewsv)constnoexcept; (1) (since C++23)constexprboolcontains(CharTc)constnoexcept; (2) (since C++23)constexprboolcontains(constCharT*s)const; (3) (since C++23)Checks if the string view contains the given substring, where

1) the substring is a string view.

2) the substring is a single character.

3) the substring is a null-terminated character string.

All three overloads are equivalent to returnfind(x)!=npos;, where x is the parameter.

Parameters

sv - a string view c - a single character s - a null-terminated character string Return value

true if the string view contains the provided substring, false otherwise.

Notes

Feature-test

macroValueStdFeature

__cpp_lib_string_contains

202011L

(C++23)contains functions Example

Run this code

#include<string_view>usingnamespacestd::literals;static_assert(// bool contains(basic_string_view x) const noexcept;"https://cppreference.com"sv.contains("cpp"sv)==trueand"https://cppreference.com"sv.contains("php"sv)==falseand// bool contains(CharT x) const noexcept;"C++23"sv.contains('+')==trueand"C++23"sv.contains('-')==falseand// bool contains(const CharT* x) const;std::string_view("basic_string_view").contains("string")==trueandstd::string_view("basic_string_view").contains("String")==false);intmain(){}See also

(C++20)

checks if the string view starts with the given prefix
(public member function)

[edit]

(C++20)

checks if the string view ends with the given suffix
(public member function)

[edit]

find characters in the view
(public member function)

[edit]

returns a substring
(public member function)

[edit]

(C++23)

checks if the string contains the given substring or character
(public member function of std::basic_string<CharT,Traits,Allocator>)

[edit]