6.23.37 wcscspn Function

Calculate the number of consecutive wide characters at the beginning of a wide string that are not contained in a set of wide characters.

Attention: This function is implemented only by MPLAB XC32 C compilers.

Include

<wchar.h>

Prototype

size_t wcscspn(const wchar_t * s1, const wchar_t * s2);

Arguments

s1
the wide string in which to search
s2
the wide characters

Return Value

Returns the length of the segment in s1 not containing wide characters found in s2.

Remarks

This function will determine the number of consecutive wide characters from the beginning of the wide string s1 that are not contained in the wide string s2.

Example

See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <wchar.h>

int main(void)
{
  wchar_t ws1[20] = L"hello";
  wchar_t ws2[20] = L"aeiou";
  wchar_t ws3[20] = L"animal";
  wchar_t ws4[20] = L"xyz";
  int res;

  res = wcscspn(ws1, ws2);
  wprintf(L"wcscspn(\"%ls\", \"%ls\") = %d\n", ws1, ws2, res);

  res = wcscspn(ws3, ws2);
  wprintf(L"wcscspn(\"%ls\", \"%ls\") = %d\n", ws3, ws2, res);

  res = wcscspn(ws3, ws4);
  wprintf(L"wcscspn(\"%ls\", \"%ls\") = %d\n", ws3, ws4, res);
}

Example Output

wcscspn("hello", "aeiou") = 1
wcscspn("animal", "aeiou") = 0
wcscspn("animal", "xyz") = 6