函数 strpbrk strcasecmp strspn

strpbrk函数

  函数原型:extern char *strpbrk(char *str1, char *str2)

  参数说明:str1待比较的字符串,str2为指定被搜索的字符串。
        
  所在库名:#include <string.h>
  
  函数功能:比较字符串str1和str2中是否有相同的字符,如果有,则返回该字符在str1中的位置的指针。
  
  返回说明:返回指针,搜索到的字符在str1中的索引位置的指针。

  例子:

  #include<string.h>
  #include<stdlib.h>
  #include <stdio.h>

  int main(int argc, char *argv[])
  {
    char *a = "aBcDeF";
    char *b = "AbCdEf";

    char* c = strpbrk(a, "c");
    printf("%s\n", c);

    return 0;
  }

  执行 cDeF

 

 

strcasecmp(忽略大小写比较字符串)

  函数原型: int strcasecmp (const char *s1, const char *s2);

  所在库名:#include <string.h>(不是C/C++的标准头文件,区别于string.h[1] )

  函数功能:用来比较参数s1和s2字符串,比较时会自动忽略大小写的差异。

  返回说明:若参数s1和s2字符串相等则返回0。s1大于s2则返回大于0 的值,s1 小于s2 则返回小于0的值。

  例子:

  #include <strings.h>
  main()
  {
    char *a="aBcDeF";
    char *b="AbCdEf";
    if(!strcasecmp(a,b))
    printf("%s=%s\n",a,b);
  }
  执行 aBcDeF=AbCdEf
  注释:该函数是二进制安全的,且对大小写不敏感。此函数只在Linux中提供,相当于windows平台的 stricmp。
 
 
strspn(返回字符串中第一个不在指定字符串中出现的字符下标)

  函数原型:size_t strspn (const char *s,const char * accept);

  所在库名:#include<string.h>

  函数功能:从参数s 字符串的开头计算连续的字符,而这些字符都完全是accept 所指字

    0 符串中的字符。简单的说,若strspn()返回的数值为n,则代表字符串s 开头连续有n 个字符都是属于字符串accept内的字符。

  返回说明:返回字符串s开头连续包含字符串accept内的字符数目。

  例子:

  #include <strings.h>
  main()
  {

    char* str = "Linux was first developed for 386/486-based pcs";
    printf("%d\n", strspn(str, "Linux"));
    printf("%d\n", strspn(str, "/-"));
    printf("%d\n", strspn(str, "1234567890"));

  }
  执行: 
    5
    0

转载于:https://www.cnblogs.com/AngelAI/p/3873714.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值