名稱空間
變體
操作

wcscspn

來自 cppreference.com
< c‎ | string‎ | wide
在標頭檔案 <wchar.h> 中定義
size_t wcscspn( const wchar_t* dest, const wchar_t* src );
(自 C95 起)

返回指向 dest 的寬字串的最長初始段的長度,該段僅由 **未** 在指向 src 的寬字串中找到的字元組成。

目錄

[編輯] 引數

dest - 指向待分析的空終止寬字串的指標
src - 指向包含要搜尋的字元的空終止寬字串的指標

[編輯] 返回值

包含僅在指向 src 的字串中未找到的字元的最長初始段的長度。

[編輯] 示例

#include <locale.h>
#include <wchar.h>
 
int main(void)
{
    wchar_t dest[] = L"白貓 黑狗 甲蟲";
    /*                      └───┐   */
    const wchar_t *src = L"甲蟲,黑狗";
 
    const size_t len = wcscspn(dest, src);
    dest[len] = L'\0'; /* terminates the segment to print it out */
 
    setlocale(LC_ALL, "en_US.utf8");
    wprintf(L"The length of maximum initial segment is %td.\n"
            L"The segment is \"%ls\".\n", len, dest);
}

輸出

The length of maximum initial segment is 3.
The segment is "白貓 ".

[編輯] 參考

  • C11 標準 (ISO/IEC 9899:2011)
  • 7.29.4.5.2 wcscspn 函式 (p: 435-436)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.24.4.5.2 wcscspn 函式 (p: 381-382)

[編輯] 另請參閱

(C95)
返回由另一個位元組字串中找到的字元組成的最大初始段的長度
僅包含在另一個寬字串中找到的寬字元
(函式) [編輯]
在另一個寬字串中查詢一個寬字串中任意寬字元的首次出現位置
(函式) [編輯]
C++ documentation for wcscspn