function
<cwchar>
wcstok
wchar_t* wcstok (wchar_t* wcs, const wchar_t* delimiters);
Split wide string into tokens
A sequence of calls to this function split wcs into tokens, which are sequences of contiguous wide characters separated by any of the wide characters that are part of delimiters.
On a first call, the function expects a C wide string as argument for wcs, whose first character is used as the starting location to scan for tokens. In subsequent calls, the function expects a null pointer and uses the position right after the end of last token as the new starting location for scanning.
This is the wide character equivalent of strtok (<cstdlib>), and operates in the same way (see strtok for more details).
Parameters
- wcs
- C wide string to truncate.
Notice that the contents of this string are modified and broken into smaller strings (tokens).
Alternativelly, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.
- delimiters
- C wide string containing the delimiter wide characters.
These may vary from one call to another.
Return Value
A pointer to the last token found in the wide string.
A null pointer is returned if there are no tokens left to retrieve.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
/* wcstok example */
#include <wchar.h>
int main ()
{
wchar_t wcs[] = L"- This, a sample string.";
wchar_t * pwc;
wprintf (L"Splitting wide string \"%ls\" into tokens:\n",wcs);
pwc = wcstok (wcs,L" ,.-");
while (pwc != NULL)
{
wprintf (L"%ls\n",pwc);
pwc = wcstok (NULL,L" ,.-");
}
return 0;
}
| |
Output:
Splitting wide string "- This, a sample string." into tokens:
This
a
sample
string
|
See also.
- strtok
- Split string into tokens (function
)
- wcscspn
- Get span until character in wide string (function
)
- wcspbrk
- Locate characters in wide string (function
)