strstr
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'header <string.h>
|
||
const char *strstr( const char* str, const char* substr ); |
||
char strstr( char* str, const char* substr ); |
||
Trova la prima occorrenza del
substr
stringa di byte nella stringa di byte puntato da str
. Original:
Finds the first occurrence of the byte string
substr
in the byte string pointed to by str
. The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
Indice |
[modifica] Parametri
str | - | puntatore alla stringa con terminazione null byte da esaminare
Original: pointer to the null-terminated byte string to examine The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
substr | - | puntatore alla stringa con terminazione null byte da ricercare
Original: pointer to the null-terminated byte string to search for The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica] Valore di ritorno
Puntatore al primo carattere della sottostringa trovato in
str
, o in mancanza di NULL sottostringa non viene trovato. Se substr
punta a una stringa vuota, viene restituito str
.Original:
Pointer to the first character of the found substring in
str
, or NULL if no such substring is found. If substr
points to an empty string, str
is returned.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[modifica] Esempio
#include <string.h> #include <stdio.h> void find_str(char const* str, char const* substr) { char* pos = strstr(str, substr); if(pos) { printf("found the string '%s' in '%s' at position: %d\n", substr, str, pos - str); } else { printf("the string '%s' was not found in '%s'\n", substr, str); } } int main(int argc, char* argv[]) { char* str = "one two three"; find_str(str, "two"); find_str(str, ""); find_str(str, "nine"); find_str(str, "n"); return 0; }
Output:
found the string 'two' in 'one two three' at position: 4 found the string '' in 'one two three' at position: 0 the string 'nine' was not found in 'one two three' found the string 'n' in 'one two three' at position: 1
[modifica] Vedi anche
trova la prima occorrenza di un carattere Original: finds the first occurrence of a character The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione) | |
trova l'ultima occorrenza di un carattere Original: finds the last occurrence of a character The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. (funzione) | |
C++ documentation for strstr
|