wchar_t* wcstok (wchar_t* wcs, const wchar_t* delimiters, wchar_t** p);
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 a similar way (see strtok for more details), but note that unlike strtok, this function takes an additional argument in which the state of the tokenization process is stored.
- 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. This requires the third argument (p) to be the same as in that previous call.
- C wide string containing the delimiter wide characters.
These may vary from one call to another.
- Pointer to a wchar_t pointer. The function uses this to store a value of type wchar_t* with the state of the current tokenization sequence. This same pointer shall be passed to the subsequent calls to this function to tokenize the rest of the wide string.
A pointer to the last token found in the wide string.
A null pointer is returned if there are no tokens left to retrieve.
/* wcstok example */
int main ()
wchar_t wcs = L"- This, a sample string.";
wchar_t * pwc;
wchar_t * pt;
wprintf (L"Splitting wide string \"%ls\" into tokens:\n",wcs);
pwc = wcstok (wcs, L" ,.-", &pt);
while (pwc != NULL)
pwc = wcstok (NULL, L" ,.-", &pt);
Splitting wide string "- This, a sample string." into tokens:
- Split string into tokens (function)
- Get span until character in wide string (function)
- Locate characters in wide string (function)