| Functions | |||||||||||||||||||||||||||||||||||||||||
| Character manipulation | |||||||||||||||||||||||||||||||||||||||||
| Conversions to and from numeric formats | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String manipulation | |||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||
| String examination | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Memory manipulation | |||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||
| Miscellaneous | |||||||||||||||||||||||||||||||||||||||||
(C11)(C11) | |||||||||||||||||||||||||||||||||||||||||
Defined in header <string.h> | ||
char* strstr(constchar* str,constchar* substr); | (1) | |
/*QChar*/* strstr(/*QChar*/* str,constchar* substr); | (2) | (since C23) |
T be an unqualified character object type.str is of typeconst T*, the return type isconstchar*.str is of typeT*, the return type ischar*.The behavior is undefined if eitherstr orsubstr is not a pointer to a null-terminated byte string.
Contents |
| str | - | pointer to the null-terminated byte string to examine |
| substr | - | pointer to the null-terminated byte string to search for |
Pointer to the first character of the found substring instr, or a null pointer if such substring is not found. Ifsubstr points to an empty string,str is returned.
#include <stdio.h>#include <string.h> void find_str(charconst* str,charconst* substr){charconst* pos= strstr(str, substr);if(pos)printf("Found the string [%s] in [%s] at position %td\n", substr, str, pos- str);elseprintf("The string [%s] was not found in [%s]\n", substr, str);} int main(void){charconst* str="one two three"; find_str(str,"two"); find_str(str,""); find_str(str,"nine"); find_str(str,"n"); return0;}
Output:
Found the string [two] in [one two three] at position 4Found the string [] in [one two three] at position 0The string [nine] was not found in [one two three]Found the string [n] in [one two three] at position 1
| finds the first occurrence of a character (function)[edit] | |
| finds the last occurrence of a character (function)[edit] | |
C++ documentation forstrstr | |