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 ...
随机推荐
- redis整理の配置
redis有一个很强大也很重要的配置文件redis.conf.此文件可以随服务启动,为服务配置各种不同场景所需的参数: daemonize: 默认情况下,redis 不是在后台运行的,如果需要在后台运 ...
- 安装MySQL提示:应用程序无法正常启动(0xc000007b)
转:https://blog.csdn.net/zztingfeng/article/details/80155624 解决:在百度上下载DirectX修复工具(增强版),修复即可. 链接:http: ...
- 纸壳CMS(ZKEACMS)体验升级,快速创建页面,直接在页面中修改内容
关于纸壳CMS 纸壳CMS又名 ZKEACMS Core 是ZKEACMS的 .net core 版本,可运行在 .net core 1.1 平台上.是一个开源的CMS. 纸壳CMS对于 ZKEACM ...
- RESTDebugger-我们的REST调试工具!!
Delphi:XE8 XE8已经为我们提供了调试REST程序的工具了,就是“RESTDebugger.exe”.这个小工具,在XE8的菜单中可以找到: 如果在这里找不到,我们可以直接在XE8的bin目 ...
- OCP最新题库收集,新版052考题及答案整理-19
19.Which is true about invalid PL/SQL objects? A) They are automatically recompiled against the new ...
- “全栈2019”Java第十一章:标识符
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- vue.js 一些知识点
vue.js 也是试图层的运用方法,跟react的方法类似,不过也有许多的不同地方: 1.vue.js 对于数据也是用{{ }} 进行数据更新: 2.vue.js 使用 v-html 指令用于输出 h ...
- [BZOJ5212][ZJOI2018]历史
传送门(洛谷) 人生第一道九条可怜……神仙操作…… 看着题解理解了一个早上才勉强看懂怎么回事…… 简化一下题目就是:已知每一个点access的总次数,求一个顺序使虚实边转化的次数最多 考虑一下,对于x ...
- 快速启动工具Rulers 4.1
Rulers 4.1 Release 360云盘 https://yunpan.cn/cSbq5nx9GVwrJ 访问密码 0532 百度云 http://pan.baidu.com/s/1czCNR ...
- spider_keeper定时任务
# Define apscheduler app 下的 __init__.py 文件中, 三个主要函数