strpbrk
来自 cppreference.cn
定义于头文件 <string.h> |
||
char *strpbrk( const char *dest, const char *breakset ); |
(1) | |
/*QChar*/ *strpbrk( /*QChar*/ *dest, const char *breakset ); |
(2) | (自 C23 起) |
1 ) 扫描由 dest 指向的以空字符结尾的字节字符串,查找来自由 breakset 指向的以空字符结尾的字节字符串的任何字符,并返回指向该字符的指针。
2) 类型通用函数,等同于 (1)。令
T
为不合格字符对象类型。- 如果
dest
的类型为 const T*,则返回类型为 const char*。 - 否则,如果
dest
的类型为 T*,则返回类型为 char*。 - 否则,行为未定义。
- 如果
如果 dest 或 breakset 不是指向以空字符结尾的字节字符串的指针,则行为未定义。
目录 |
[编辑] 参数
dest | - | 指向要分析的以空字符结尾的字节字符串的指针 |
breakset | - | 指向包含要搜索的字符的以空字符结尾的字节字符串的指针 |
[编辑] 返回值
指向 dest 中同时也在 breakset 中的第一个字符的指针,如果不存在这样的字符,则返回空指针。
[编辑] 注意
名称代表“字符串指针断点”,因为它返回一个指向第一个分隔(“断点”)字符的指针。
[编辑] 示例
运行此代码
#include <stdio.h> #include <string.h> int main(void) { const char* str = "hello world, friend of mine!"; const char* sep = " ,!"; unsigned int cnt = 0; do { str = strpbrk(str, sep); // find separator if(str) str += strspn(str, sep); // skip separator ++cnt; // increment word count } while(str && *str); printf("There are %u words\n", cnt); }
输出
There are 5 words
[编辑] 参考
- C23 标准 (ISO/IEC 9899:2024)
- 7.24.5.4 strpbrk 函数(p: 待定)
- C17 标准 (ISO/IEC 9899:2018)
- 7.24.5.4 strpbrk 函数(p: 待定)
- C11 标准 (ISO/IEC 9899:2011)
- 7.24.5.4 strpbrk 函数(p: 368)
- C99 标准 (ISO/IEC 9899:1999)
- 7.21.5.4 strpbrk 函数(p: 331)
- C89/C90 标准 (ISO/IEC 9899:1990)
- 4.11.5.4 strpbrk 函数
[编辑] 另请参见
返回由另一个字节字符串中找到的字符组成的最大初始段的长度 仅由另一个字节字符串中未找到的字符组成 (函数) | |
查找字符的第一次出现 (函数) | |
(C11) |
查找字节字符串中的下一个标记 (函数) |
C++ 文档,关于 strpbrk
|