C Standard Libraries C++

wcsstr()

Declaration

wchar_t* wcsstr(const wchar_t* kwpString, const wchar_t* kwpSearch);

Description

This function searches the wide-character string "kwpString" for occurrences of the string "kwpSearch." The function returns a pointer to the first instance of "kwpSearch" in "kwpString." If "kwpSearch" cannot be found in "kwpString," the function returns NULL.

Example

#include <cwchar>

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

    // Search the string for the first occurence of a substring
    wchar_t* wpLocation = wcsstr(waString, waSubstring);
    wprintf(L"Searching \"%ws\" for \"%ws\"\n",
        waString, waSubstring);
    wprintf(L"The substring was found at \"%ws\"\n", wpLocation);

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

Output

wcsstr() Output
 

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