C Standard Libraries C++

wcstok()

Declaration

wchar_t* wcstok(wchar_t* wpString, const wchar_t* kwpDelim);

Description

This function uses the set of wide-characters in the string "kwpDelim" to tokenize the string "wpString." The function sets each successive delimiter found in "wpString" to NULL (or 0) and returns a pointer to the first character after the last NULL. The function is called the first time with the string that is to be tokenized passed in as "wpString." Remaining calls use NULL for this parameter. The function returns NULL when no more delimiters are found in "wpString."

Example

#include <cwchar>

int main()
{
    wchar_t waString[] = L"XoaX.net Video Tutorials";
    wchar_t waDelimiters[] = L". ";

    wprintf(L"Tokenize \"%ws\" with \"%ws\":\n",
        waString, waDelimiters);
    // Set the first delimeter to NULL and return "waString"
    wchar_t* wpSubstring = wcstok(waString, waDelimiters);

    while (wpSubstring) {
        wprintf(L"%ws\n", wpSubstring);
        // Nullify the next delimiter, return the start
        wpSubstring = wcstok(NULL, waDelimiters);
    }

    // Keep the window open until "Enter" is pressed
    getwchar();
    return 0;
}

Output

wcstok() Output
 

© 2007–2024 XoaX.net LLC. All rights reserved.