wcscspn
来自cppreference.com
| 在标头 <wchar.h> 定义
|
||
| |
(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'; /* 终止字符串,以便显示 */
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 "白猫 ".