Xi Xu's More Things

wcspbrk

来自cppreference.com
< c‎ | string‎ | wide
 
 
 
空终止宽字符串
函数
字符操作
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C99)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
转换成数值格式
(C95)(C99)
(C95)(C99)
(C99)(C95)(C99)
(C99)(C99)
字符串操作
(C95)(C11)
(C95)(C11)
(C95)(C11)
(C95)(C11)
(C95)(C11)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
(C95)
wcspbrk
(C95)
(C95)
(C95)
(C95)(C11)
数组操作
(C95)(C11)
(C95)(C11)
(C95)
(C95)
(C95)
 
在标头 <wchar.h> 定义
wchar_t* wcspbrk( const wchar_t* dest, const wchar_t* str );
(C95 起)

dest 所指向的宽字符串中,寻找首个亦在 str 所指向的宽字符串中的字符。

参数

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.

引用

  • C11 标准(ISO/IEC 9899:2011):
  • 7.29.4.5.3 The wcspbrk function (第 436 页)
  • C99 标准(ISO/IEC 9899:1999):
  • 7.24.4.5.3 The wcspbrk function (第 382 页)

参阅

(C95)
返回仅由出现于另一个宽字符串中的宽字符分隔的最长首段长度
(函数)
(C95)
查找宽字符在宽字符串中的首次出现
(函数)
查找一个字符串中的任意一个字符在另一个字符串中的首个位置
(函数)