函式
<cwchar>

wcsspn

size_t wcsspn (const wchar_t* wcs1, const wchar_t* wcs2);
獲取寬字串中的字元集跨度
返回 wcs1 中僅由 wcs2 中的寬字元組成的初始部分的長度。

搜尋不包括任一字串的終止空寬字元,而是在那裡結束。

這是 strspn (<cstring>) 的寬字元等效函式。

引數

wcs1
要被掃描的 C 寬字串。
wcs2
包含要匹配的字元的 C 寬字串。

返回值

wcs1 中僅包含 wcs2 中的寬字元的初始部分的長度。
因此,如果 wcs1 中的所有寬字元都在 wcs2 中,則函式返回整個 wcs1 寬字串的長度;如果 wcs1 中的第一個寬字元不在 wcs2 中,則函式返回零。
size_t 是一個無符號整數型別。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
/* wcsspn example */
#include <wchar.h>

int main ()
{
  int i;
  wchar_t wcsText[] = L"129th";
  wchar_t wcsSet[] = L"1234567890";

  i = wcsspn (wcsText,wcsSet);
  wprintf (L"The initial number has %d digits.\n",i);
  return 0;
}

輸出

The initial number has 3 digits.


另見