function
<cstring>
strstrconst char * strstr ( const char * str1, const char * str2 ); char * strstr ( char * str1, const char * str2 );
Locate substring
Returns a pointer to the first occurrence of str2 in str1, or a null pointer if str2 is not part of str1.The matching process does not include the terminating null-characters, but it stops there.
char * strstr ( const char *, const char * );
instead of the two overloaded versions provided in C++.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* strstr example */
#include <stdio.h>
#include <string.h>
int main ()
{
char str[] ="This is a simple string";
char * pch;
pch = strstr (str,"simple");
if (pch != NULL)
strncpy (pch,"sample",6);
puts (str);
return 0;
}
This example searches for the "simple" substring in str and replaces that word for "sample".
Output:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4