wcscspn
From cppreference.net
Null-terminated wide strings
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<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 "白猫 ".