首页 技术 正文
技术 2022年11月15日
0 收藏 953 点赞 4,745 浏览 2037 个字

strspn

  • Returns the length of the initial portion of str1 which consists only of characters that are part of str2.
  • The search does not include the terminating null-characters of either strings, but ends there.
  • 检索字符串 dest 中第一个不在字符串 src 中出现的字符下标。返回 dest 所指向的空终止字节串的最大起始段( span )长度,段仅由 src 所指向的空终止字节字符串中找到的字符组成。
  • 若 dest 或 src 不是指向空终止字节字符串的指针,则行为未定义。
size_t strspn( const char *dest, const char *src );

Parameters

dest

  • C string to be scanned.
  • 指向要分析的空终止字节字符串的指针

src

  • C string containing the characters to match.
  • 指向含有要搜索的字符的空终止字节字符串的指针

Return value

  • The length of the initial portion of str1 containing only characters that appear in str2.

    Therefore, if all of the characters in str1 are in str2, the function returns the length of the entire str1 string, and if the first character in str1 is not in str2, the function returns zero.

    size_t is an unsigned integral type.

  • 仅由来自 src 所指向的空终止字节字符串的字符组成的最大起始段长度。

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

Example

//
// Created by zhangrongxiang on 2018/2/5 17:28
// File strspn
//#include <stdio.h>
#include <string.h>//C 库函数 size_t strspn(const char *str1, const char *str2) 检索字符串 str1 中第一个不在字符串 str2 中出现的字符下标。int main() {
size_t len;
const char str1[] = "ABCDEFG02018ABCDEFG02018";
const char str2[] = "ABCD";
const char str3[] = "2018";
const char str4[] = "AB";
const char str5[] = "AC";
const char str6[] = "aC";
len = strspn(str1, str2);
printf("%d\n", (unsigned int) len); //4
len = strspn(str1, str3);
printf("%d\n", (unsigned int) len); //0
len = strspn(str1, str4);
printf("%d\n", (unsigned int) len); //2
len = strspn(str1, str5);
printf("%d\n", (unsigned int) len); //1
len = strspn(str1, str6);
printf("%d\n", (unsigned int) len); //0 char strtext[] = "129th";
char cset[] = "1234567890"; len = strspn(strtext, cset);
printf("The initial number has %d digits.\n", (int) len);//3 const char *string = "abcde312$#@";
const char *low_alpha = "qwertyuiopasdfghjklzxcvbnm"; len = strspn(string, low_alpha);
printf("%d\n",(int)len);//5
//After skipping initial lowercase letters from 'abcde312$#@'
printf("After skipping initial lowercase letters from '%s'\n"
"The remainder is '%s'\n", string, string + len);//The remainder is '312$#@' return (0);
}

参考文章

转载注明出处

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,493
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,495
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,133
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,297