std::strstr
提供: cppreference.com
<tbody>
</tbody>
| ヘッダ <cstring> で定義
|
||
const char* strstr( const char* str, const char* target ); |
||
char* strstr( char* str, const char* target ); |
||
str の指すバイト文字列内のバイト文字列 target が現れる最初の位置を探します。 終端のヌル文字は比較されません。
引数
| str | - | 調べるヌル終端バイト文字列を指すポインタ |
| target | - | 検索するヌル終端バイト文字列を指すポインタ |
戻り値
str 内の見つかった部分文字列の最初の文字を指すポインタ、またはそのような文字が見つからない場合は NULL。 target が空文字列を指す場合は、 str が返されます。
例
Run this code
#include <iostream>
#include <cstring>
int main()
{
const char *str = "Try not. Do, or do not. There is no try.";
const char *target = "not";
const char *result = str;
while ((result = std::strstr(result, target)) != NULL) {
std::cout << "Found '" << target
<< "' starting at '" << result << "'\n";
// Increment result, otherwise we'll find target at the same location
++result;
}
}
出力:
Found 'not' starting at 'not. Do, or do not. There is no try.'
Found 'not' starting at 'not. There is no try.'
関連項目
| 文字列内の文字を探します ( std::basic_string<CharT,Traits,Allocator>のパブリックメンバ関数)
| |
| 別のワイド文字列中のワイド文字列が現れる最初の位置を探します (関数) | |
| 文字が現れる最初の位置を探します (関数) | |
| 文字が現れる最後の位置を探します (関数) | |
strstr の C言語リファレンス
| |