wcsstr() — Locate Wide-Character Substring

Format

#include <wchar.h>
wchar_t *wcsstr(const wchar_t *wcs1, const wchar_t *wcs2);

Language Level: ANSI

Threadsafe: Yes.

Wide Character Function: See Wide Characters for more information.

Description

The wcsstr() function locates the first occurrence of wcs2 in wcs1.

Return Value

The wcsstr() function returns a pointer to the beginning of the first occurrence of wcs2 in wcs1. If wcs2 does not appear in wcs1, the wcsstr() function returns NULL. If wcs2 points to a wide-character string with zero length, it returns wcs1.

Example that uses wcsstr()

This example uses the wcsstr() function 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



[ Top of Page | Previous Page | Next Page | Contents | Index ]