C Standard Libraries C++

wcsspn()

Declaration

size_t wcsspn(const wchar_t* kwpString, const wchar_t* kwpNotSet);

Description

This function searches the wide-character string "kwpString" for the first instance of a character that is not in the null-terminated character set "kwpNotSet" and returns the index of the location in "kwpString" if the search was successful. Otherwise, the length of "kwpString" is returned to indicate that all of the characters are in the string.

Example

#include <cwchar>

int main()
{
    wchar_t waString[] = L"XoaX.net";
    wchar_t waNotSet[] = L"Xnt";

    // Search for a character that is not in a set
    int iLocation = wcsspn(waString, waNotSet);
    wprintf(L"Searching \"%ws\" for characters not in \"%ws\"\n",
        waString, waNotSet);
    wprintf(L"Found \"%wc\" at index %d\n",
        waString[iLocation], iLocation);

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

Output

wcsspn() Output
 

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