C 库函数 - strcspn()

C 语言教程 · 2019-02-24 15:59:36

描述

C 库函数 size_t strcspn(const char *str1, const char *str2) 检索字符串 str1 开头连续有几个字符都不含字符串 str2 中的字符。

声明

下面是 strcspn() 函数的声明。

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

参数

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

返回值

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

实例

下面的实例演示了 strcspn() 函数的用法。

#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

点击查看所有 C 语言教程 文章: https://codercto.com/courses/l/17.html

查看所有标签

Math Adventures with Python

Math Adventures with Python

Peter Farrell / No Starch Press / 2018-11-13 / GBP 24.99

Learn math by getting creative with code! Use the Python programming language to transform learning high school-level math topics like algebra, geometry, trigonometry, and calculus! In Math Adventu......一起来看看 《Math Adventures with Python》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试