再牛逼的梦想也抵不住傻逼似的坚持!   设为首页 - 加入收藏
您的当前位置:小鱼资料库 > 计算机 > C语言 > 正文

strspn-C语言标准库|

来源:网络 编辑:雨凉 时间:2022-06-19

C 库函数 - strspn()


描述

C 库函数 size_t strspn(const char *str1, const char *str2) 检索字符串 str1 中第一个不在字符串 str2 中出现的字符下标。

声明

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

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

参数

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

返回值

该函数返回 str1 中第一个不在字符串 str2 中出现的字符下标。

实例

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

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

int main ()
{
   int len;
   const char str1[] = "ABCDEFG019874";
   const char str2[] = "ABCD";

   len = strspn(str1, str2);

   printf("初始段匹配长度 %d
", len );

   return(0);
}

让我们编译并运行上面的程序,这将产生以下结果:

初始段匹配长度 4
标签:

小鱼资料库 www.xiaoyuzl.com

Copyright © 2020-2022 XIAOYUZL. All rights reserved. 冀ICP备2020029262号-2

声明:本站分享的文章、资源等均由网友上传,版权归原作者所有,只用于搜集整理。如有侵权,请您与站长联系,我们将及时处理!

Top