wcspbrk
来自cppreference.com
| 在标头 <wchar.h> 定义
|
||
| |
(1) | (C95 起) |
| |
(2) | (C23 起) |
1) 在
dest 所指向的宽字符串中,寻找首个亦在 str 所指向的宽字符串中的字符。2) 等价于 (1) 的泛型函数。令
T 为未限定的 宽字符对象类型。
- 若
dest类型为const T*,则返回类型为const wchar_t*。 - 否则,若
dest类型为T*,返回类型为wchar_t*。 - 否则,行为未定义。
- 若
(wcspbrk) 或使用了函数指针时),则实际函数声明 (1) 即变得可见。参数
| dest | - | 指向要分析的空终止宽字符串的指针 |
| src | - | 指向含有待搜索字符的空终止宽字符串的指针 |
返回值
指向 dest 中首个亦在 str 中的首个字符的指针,或若这种字符不存在则为空指针。
注解
名字代表“宽字符串指针打断 (wide character string pointer break)”,因为它返回指向首个分隔符(“打断”)的指针。
示例
运行此代码
#include <stdio.h>
#include <wchar.h>
int main(void)
{
const wchar_t* str = L"Hello world, friend of mine!";
const wchar_t* sep = L" ,!";
unsigned int cnt = 0;
do {
str = wcspbrk(str, sep); // 寻找分隔符
if (str) str += wcsspn(str, sep); // 跳过分隔符
++cnt; // 增加词计数
} while (str && *str);
wprintf(L"There are %u words.\n", cnt);
}
输出:
There are 5 words.