6.23.46 wcsspn Function

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

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

Include

<wchar.h>

Prototype

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

Arguments

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

Return Value

Returns the length of the segment in s1 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 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 = wcsspn(ws1, ws2);
  wprintf(L"wcsspn(\"%ls\", \"%ls\") = %d\n", ws1, ws2, res);

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

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

Example Output

wcsspn("hello", "aeiou") = 0
wcsspn("animal", "aeiou") = 1
wcsspn("animal", "xyz") = 0