function
<cwchar>

wcschr

const wchar_t* wcschr (const wchar_t* ws, wchar_t wc); wchar_t* wcschr ( wchar_t* ws, wchar_t wc);
Locate first occurrence of character in wide string
Returns a pointer to the first occurrence of the wide character wc in the C wide string ws.

The terminating null wide character is considered part of the string. Therefore, it can also be located in order to retrieve a pointer to the end of a wide string.

This is the wide character equivalent of strchr (<cstring>).

Parameters

ws
C wide string.
wc
Wide character to be located.

Return Value

A pointer to the first occurrence of wc in ws.
If wc is not found, the function returns a null pointer.

Portability

In C, this function is only declared as:

wchar_t * wcschr ( const wchar_t *, wchar_t );

instead of the two overloaded versions provided in C++.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/* wcschr example */ #include <wchar.h> int main () { wchar_t wcs[] = L"This is a sample wide string"; wchar_t * pwc; wprintf (L"Looking for the 's' character in \"%ls\"...\n",wcs); pwc=wcschr(wcs,L's'); while (pwc!=NULL) { wprintf (L"found at %d\n",pwc-wcs+1); pwc=wcschr(pwc+1,L's'); } return 0; }

Output:
 Looking for the 's' character in "This is a sample string"... found at 4 found at 7 found at 11 found at 23 


See also