C++ <cwchar> - wcscspn() Function
The C++ <cwchar> strspn() function returns the length of maximum initial segment (span) of the wide string pointed to by ws1 which consists of only the characters not present in the wide string pointed to by ws2.
The search includes the terminating null wide characters and hence returns the length of ws1 when none of the characters of ws2 are found in ws1.
Syntax
size_t wcscspn (const wchar_t* ws1, const wchar_t* ws2);
Parameters
ws1 |
Specify pointer to the null-terminated wide string to be scanned. |
ws2 |
Specify pointer to the null-terminated wide string containing the characters to match. |
Return Value
Returns the length of the initial part of ws1 not containing any of the wide characters present in ws2. Returns the length of ws1 when none of the wide characters of ws2 are found in ws1.
Example:
The example below shows the usage of wcscspn() function.
#include <iostream> #include <cwchar> using namespace std; int main (){ wchar_t ws1[100] = L"12345@ABWzx3423S#"; wchar_t ws2[100] = L"#@,"; //finding the length of maximum initial length of //ws1 not containing any wide characters of ws2 int max_initial_len = wcscspn(ws1, ws2); //displaying the result cout<<"Length of maximum initial length: " <<max_initial_len; return 0; }
The output of the above code will be:
Length of maximum initial length: 5
❮ C++ <cwchar> Library