Home C&C++函数库 c++ 语法 程序源码 Linux C库

strcspn

函数   <cstring>

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


获取字符串中部分字符

扫描str1中属于str2的任何字符的第一次出现,返回在第一次出现之前读取的str1字符数。

搜索包括结束空字符。因此,如果在str1中没有找到str2的字符,该函数将返回str1的长度。

☲  参数


str1
要扫描的C字符串。

str2
包含要匹配的字符的C字符串。

☉  返回值



不包含属于str2的任何字符的str1开头部分的长度。
如果str2中的字符在str1中没有找到,返回str1的长度。
size_t是一个无符号整型。

☣  示例



/* strcspn example */
#include <stdio.h>
#include <string.h>

int main ()
{
  char str[] = "fcba73";
  char keys[] = "1234567890";
  int i;
  i = strcspn (str,keys);
  printf ("The first number in str is at position %d.\n",i+1);
  return 0;
}

输出:
The first number in str is at position 5

🍄  另请参阅



strspn 获取字符串中字符集的范围(function )
strpbrk 定位字符串中的字符(function )
strstr 查找子字符串(function )
strncmp 比较两个字符串中的字符(function )

联系我们 免责声明 关于CandCplus 网站地图