C 标准库 - string.h之strspn使用
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);
}
参考文章
- http://www.runoob.com/cprogramming/c-function-strspn.html
- http://www.cplusplus.com/reference/cstring/strspn/
- http://zh.cppreference.com/w/c/string/byte/strspn
转载注明出处
C 标准库 - string.h之strspn使用的更多相关文章
- C 标准库 - string.h
C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...
- C标准库<string.h>实现
本文地址:http://www.cnblogs.com/archimedes/p/c-library-string.html,转载请注明源地址. 1.背景知识 <string.h>中声明的 ...
- C 标准库 - string.h之strpbrk使用
strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...
- C标准库string.h中几个常用函数的使用详解
strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...
- C 标准库 - string.h之memmove使用
memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...
- C 标准库 - string.h之memcpy使用
memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...
- C 标准库 - string.h之memcmp使用
memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...
- C 标准库 - string.h之memchr使用
memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...
- C 标准库 - string.h之strlen使用
strlen Returns the length of the C string str. The length of a C string is determined by the termina ...
随机推荐
- .net 委托的简化语法
1. 不需要构造委托对象 ThreadPool.QueueUserWorkItem:通过线程池 public static void WorkItem() { ThreadPool.QueueUser ...
- 基于JSP的B2C的网上拍卖系统_秒杀与竞价-JavaWeb项目-有源码
开发工具:Myeclipse/Eclipse + MySQL + Tomcat 项目简介: 基于B2C的网上拍卖系统主要用于帮助人们应用互联网方便快捷买到自己所中意的商品,并参与到秒杀与竞拍当中.主要 ...
- TSQL--NESTED LOOPS JOIN
算法:遍历外表,将遍历出结果依次在内标中匹配查找 --如果内表无索引,则扫描内表 foreach(row r1 in outerTable) { foreach(row r2 in innerTabl ...
- Python 单元测试 增强系统健壮性
问题背景交代 注意,JulyNovel只爬取免费小说,所有vip章节全部导航至起点网站,遵循robots协议,所有数据仅供学习用途,侵删 通过编写单元测试,提高JulyNovel系统可靠性 首先我们知 ...
- zookeeper 开机启动
第一种:直接修改/etc/rc.d/rc.local文件 在/etc/rc.d/rc.local文件中需要输入两行,其中export JAVA_HOME=/usr/java/jdk1.8.0_112是 ...
- 【题解】 UOJ #2. 【NOI2014】起床困难综合症
传送门 不是很简单? 考虑一下这个数的二进制位是什么,要么是1,要么是0. 然后怎么做? 因为一开始可以选0~m的数,那么二进制为中全是0的肯定是可以选的. 接着考虑全是1的怎么选? 如果全都是1的而 ...
- “全栈2019”Java第七十八章:内部类可以继承其他类吗?
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- “全栈2019”Java第六十七章:内部类、嵌套类详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- NOI2017 酱油记
侥幸混进市队让我晚退役了几个月..不过终究还是退役了呢..这应该是最后一篇游记了吧.. 考前半个月都在安徽集训..然后发现所有人都停课集训..只有我暑假了开始.. 反正上课各种听不懂..各种被大佬虐. ...
- ArchLinux "error: required key missing from keyring"
downloading required keys... error: key "C847B6AEB0544167" could not be looked up remotely ...