函式
<cwchar>

wcscspn

size_t wcscspn (const wchar_t* wcs1, const wchar_t* wcs2);
在寬字串中獲取直到某個字元的跨度
掃描 wcs1,查詢 wcs2 中任意一個字元的首次出現,返回讀取的 wcs1 中直到該首次出現為止的字元數。

該搜尋包含終止的空寬字元。因此,如果 wcs2 中的字元在 wcs1 中未找到,則函式將返回 wcs1 的長度。

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

引數

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

返回值

wcs1 的初始部分中不包含 wcs2 中任何字元的字元數。
如果 wcs2 中的任何寬字元未在 wcs1 中找到,則此值為 wcs1 的長度。
size_t 是一個無符號整數型別。

示例

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

int main ()
{
  wchar_t wcs[] = L"fcba73";
  wchar_t keys[] = L"1234567890";
  int i;
  i = wcscspn (wcs,keys);
  wprintf (L"The first number in wcs is at position %d.\n",i+1);
  return 0;
}

輸出

The first number in wcs is at position 5


另見