C <wchar.h> - wcsspn() Function
The C <wchar.h> wcsspn() function returns the length of maximum initial segment (span) of the wide string pointed to by ws1 which consists of only the wide characters present in the wide string pointed to by ws2.
Syntax
size_t wcsspn (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 wide characters to match. |
Return Value
Returns the length of maximum initial segment of ws1 which consists of only the wide characters present in ws2.
Example:
The example below shows the usage of wcsspn() function.
#include <stdio.h> #include <wchar.h> int main (){ wchar_t str1[100] = L"12345ABWzx3423Sx"; wchar_t str2[100] = L"1234567890"; //finding the length of maximum initial segment of //str1 containing only the wide characters of str2 int max_initial_len = wcsspn(str1, str2); //displaying the result printf("Length of maximum initial length: %d\n", max_initial_len); return 0; }
The output of the above code will be:
Length of maximum initial length: 5
❮ C <wchar.h> Library