C 库函数 - strcspn()

 

定义

size_t strcspn(const char *str1, const char *str2)

参数

str1 -- 要被检索的 C 字符串。
str2 -- 该字符串包含了要在 str1 中进行匹配的字符列表。

描述

该函数返回 str1 开头连续都不含字符串 str2 中字符的字符数。

 

例子

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

int main ()
{
   int len;
   const char str1[] = "ABCDEF4960910";
   const char str2[] = "013";

   len = strcspn(str1, str2);

   printf("第一个匹配的字符是在 %d\n", len + 1);
   return(0);
}

输出

第一个匹配的字符是在 10

 

参考:

https://www.runoob.com/cprogramming/c-function-strcspn.html

 

 

posted @ 2019-07-20 23:24  anobscureretreat  阅读(211)  评论(0编辑  收藏  举报