char *strpbrk(const char *s1, const char *s2)
函数说明:strpbrk是在字符串(s1)中找出最先含有搜索字符串(s2)中任一字符的位置并返回,若找不到则返回空指针。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char *s1="Xiyou Linux Group";
char *s2="Linux";
char *p;
/*Example 1*/
p=strpbrk(s1,s2);
if(p)
{
printf("%s\n",p);
}
else
{
printf("Not Found!\n");
}
//输出结果为:iyou Linux Group
/*Example 2*/
p=strpbrk(s1, "hhhhhhh");
if(p)
{
printf("%s",p);
}
else
{
printf("Not Found!\n");
}
return 0;
}
//输出结果为:Not Found!
char *strrchr(const char *str, char c)
函数的作用:在原字符串str中找到字符c最后一次出现的位置
#include<stdio.h>
#include<string.h>
int main(){
char arr[100] = "hello world hello world hello world";
char* ret = strrchr(arr,'w');
//在字符串arr中最后出现的字符'w'的地址
printf("%d ",ret-arr);//指针相减==元素之间的个数
return 0;
}
size_t strspn(char const *str, char const *grouo)
函数说明:看str中是不是连续往后每个字符都在group中可以找到。到第一个不在gruop的元素为止。看从str第一个开始,前面的字符有几个在group中
#include <stdio.h>
#include <string >;
int main() {
int len1, len2;
char buffer[] = "25,142,330,Smith,J,239-4123";
len1 = strspn(buffer, "0123456789");
len2 = strspn(buffer, ",0123456789");
printf(" len1为:%d; len2为:%d", len1, len2);
getchar();
return 0;
}
}
其中len1为:2 ,len2为:11