std::basic_string<CharT,Traits,Allocator>::starts_with
ja.cppreference.net より
constexpr bool
starts_with( std::basic_string_view<CharT,Traits> sv ) const noexcept;
|
(1) | (C++20以降) |
constexpr bool
starts_with( CharT ch ) const noexcept;
|
(2) | (C++20以降) |
constexpr bool
starts_with( const CharT* s ) const;
|
(3) | (C++20以降) |
文字列が指定された接頭辞で始まるかどうかを調べます。接頭辞は以下のいずれかです。
1) 文字列ビュー
sv (これは別のstd::basic_stringからの暗黙の変換の結果である可能性があります)。2) 単一の文字
ch。3) ヌル終端文字列
s。3つのオーバーロードはすべて実質的に std::basic_string_view<CharT, Traits>(data(), size()).starts_with(x) を返します。ここで x はパラメータです。
パラメータ
| sv | - |
他のstd::basic_stringからの暗黙変換の結果である可能性のある文字列ビュー
|
| ch | - | 単一の文字 |
| s | - | ヌル終端文字列 |
戻り値
true 文字列が指定された接頭辞で始まる場合、 false それ以外の場合。
注記
| 機能テスト マクロ | 値 | 標準 | 機能 |
|---|---|---|---|
__cpp_lib_starts_ends_with
|
201711L
|
(C++20) | 文字列の接頭辞と接尾辞のチェック: starts_with() および ends_with() |
例
このコードを実行
#include <cassert> #include <string> #include <string_view> int main() { using namespace std::literals; const auto str = "Hello, C++20!"s; assert ("" && str.starts_with("He"sv) // (1) && !str.starts_with("he"sv) // (1) && str.starts_with("He"s) // (1) implicit conversion string to string_view && !str.starts_with("he"s) // (1) implicit conversion string to string_view && str.starts_with('H') // (2) && !str.starts_with('h') // (2) && str.starts_with("He") // (3) && !str.starts_with("he") // (3) ); }
関連項目
|
(C++20)
|
文字列が指定された接尾辞で終わるかどうかをチェックする
(公開メンバ関数) |
|
(C++20)
|
文字列ビューが指定された接頭辞で始まるかどうかをチェックする
( std::basic_string_view<CharT,Traits>の公開メンバ関数)
|
|
(C++20)
|
文字列ビューが指定された接尾辞で終わるかどうかをチェックする
( std::basic_string_view<CharT,Traits>の公開メンバ関数)
|
|
(C++23)
|
文字列が指定された部分文字列または文字を含むかどうかをチェックする
(公開メンバ関数) |
|
(C++23)
|
文字列ビューが指定された部分文字列または文字を含むかどうかをチェックする
( std::basic_string_view<CharT,Traits>の公開メンバ関数)
|
|
2つの文字列を比較する
(公開メンバ関数) |
|
|
部分文字列を返す
(公開メンバ関数) |