C <wchar.h> - wcsstr() Function
The C <wchar.h> wcsstr() function is used to find the first occurrence of the wide string ws2 in the wide string pointed to by ws1. The terminating null characters are not compared.
The function returns pointer to the first occurrence of ws2 in ws1, or null pointer if ws2 is not found in ws1.
Syntax
const wchar_t* wcsstr (const wchar_t* ws1, const wchar_t* ws2); wchar_t* wcsstr (wchar_t* ws1, const wchar_t* ws2);
Parameters
ws1 |
Specify pointer to the null-terminated wide string to be searched in. |
ws2 |
Specify pointer to the null-terminated wide string to be searched for. |
Return Value
Returns pointer to the first occurrence of ws2 in ws1, or null pointer if ws2 is not found in ws1.
Example:
The example below shows the usage of wcsstr() function.
#include <stdio.h> #include <wchar.h> int main (){ wchar_t MyStr[100] = L"To be, or not to be, that is the question."; wchar_t * search; //searching for first occurrence of "be" search = wcsstr(MyStr, L"be"); //displaying the result if(search != NULL) printf("First occurrence of 'be' starts at: %ld\n", (search-MyStr+1)); else printf("Not Found.\n"); return 0; }
The output of the above code will be:
First occurrence of 'be' starts at: 4
❮ C <wchar.h> Library