Syntax
#include <wchar.h> wchar_t *wcsstr(const wchar_t *wcs1, const wchar_t *wcs2);Description
wcsstr locates the first occurrence of wcs2 in wcs1. In the matching process, wcsstr ignores the wchar_t null character that ends wcs2.
The behavior of wcsstr is affected by the LC_CTYPE category of the current locale.
wcsstr returns a pointer to the beginning of the first occurrence of wcs2 in wcs1. If wcs2 does not appear in wcs1, wcsstr returns NULL. If wcs2 points to a wide-character string with zero length, wcsstr returns wcs1.
This example uses wcsstr to find the first occurrence of hay in the wide-character string needle in a haystack.
#include <stdio.h>
#include <wchar.h>
int main(void)
{
wchar_t *wcs1 = L"needle in a haystack";
wchar_t *wcs2 = L"hay";
printf("result: \"%ls\"\n", wcsstr(wcs1, wcs2));
return 0;
/****************************************************************************
The output should be similar to :
result: "haystack"
****************************************************************************/
}
Related Information