(standard c libraries translation )strpbrk

来源:互联网 发布:2kol球员数据更新2017 编辑:程序博客网 时间:2024/04/29 05:25
strpbrk - search a string for any of a set of bytes

所需头文件
#include <string.h>

char *strpbrk(const char *s, const char *accept);

The strpbrk() function locates the first occurrence in the string s of any of the bytes in the string accept.
The strpbrk() function returns a pointer to the byte in s that matches one of the bytes in accept, or NULL if no such byte is found.
strpbrk函数定位字符串s中第一次出现字符串accept中的字节的位置

strpbrk函数返回指向s中第一次出现accept中字节的问题,如果没有这个字节则返回NULL


testcase如下:

#include <stdio.h>#include <string.h>int main(void){const char *dest = "abc12cba";const char *accept1 = "xyz12";const char *accept2 = "xyz";char *tmp = NULL;tmp = strpbrk(dest, accept1);printf("tmp = %s\n", tmp);tmp = strpbrk(dest, accept2);if (tmp == NULL) {printf("tmp is null\n");}return 0;}

运行结果如下:

cheny.le@cheny-ThinkPad-T420:~/cheny/testCode$ ./a.out
tmp = 12cba
tmp is null

这个函数的主要功能就是在一个字符串中查找指定的字符集

0 0
原创粉丝点击