function
<cwchar>
wcsstr
const wchar_t* wcsstr (const wchar_t* wcs1, const wchar_t* wcs2);
wchar_t* wcsstr ( wchar_t* wcs1, const wchar_t* wcs2);
Locate substring of wide string
Returns a pointer to the first occurrence of wcs2 in wcs1, or a null pointer if wcs2 is not part of wcs1.
The matching process does not include the terminating null wide characters, but it stops there.
This is the wide character equivalent of strstr (<cstring>).
Parameters
- wcs1
- C wide string to be scanned.
- wcs2
- C wide string containing the sequence of characters to match.
Return Value
A pointer to the first occurrence in wcs1 of the entire sequence of characters specified in wcs2, or a null pointer if the sequence is not present in wcs1.
Portability
In C, this function is only declared as:
wchar_t * wcsstr ( const wchar_t *, const wchar_t * );
instead of the two overloaded versions provided in C++.
Example
1 2 3 4 5 6 7 8 9 10 11 12
|
/* wcsstr example */
#include <wchar.h>
int main ()
{
wchar_t wcs[] = L"This is a simple string";
wchar_t * pwc;
pwc = wcsstr (wcs,L"simple");
wcsncpy (pwc,L"sample",6);
wprintf (L"%ls\n",wcs);
return 0;
}
|
This example searches for the L"simple" substring in wcs and replaces that word for L"sample".
Output:
See also
- strstr
- Locate substring (function
)
- wcsspn
- Get span of character set in wide string (function
)
- wcspbrk
- Locate characters in wide string (function
)
- wcschr
- Locate first occurrence of character in wide string (function
)