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 ...
随机推荐
- memcached整理の实践
对于memcached使用内存来存取数据,一般情况下,速度比直接从数据库或者文件系统存取要快,memcached最常用的场景是利用其“存取快”来保护数据库,防止高频率存取数据库. 缓存数据库查询结果 ...
- CentOS6.5安装mysql-5.7.18-1.el6.x86_64.rpm-bundle.tar
本文内容为转载内容,具体作者忘记是谁了,在收藏夹找到的 先去官网(https://dev.mysql.com/downloads/mysql/),在Select Operating System选择R ...
- 虚拟化 - Docker
Docker Desktop (for windows and mac) Docker Desktop 注意 安装时有可能卡主,可以关掉重新装 重启启动时,可能报错"VIRTUALIZATI ...
- 17、xtrabackup 常用备份功能与选项
并行备份 > innobackupex -p123123 --parallel=8 /backup 节流备份 > innobackupex -p123123 --throttle=200 ...
- “全栈2019”Java第五十二章:继承与初始化详解
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- 关于react的一些疑问点
参考转载:链接:http://www.jianshu.com/p/83bda9cd8c67 1.refs <input type="text" ref="input ...
- HTML5 调用百度地图API地理定位
<!DOCTYPE html> <html> <title>HTML5 HTML5 调用百度地图API地理定位实例</title> <head&g ...
- SQLServer XML
OPENXML 参见:OPENXML (SQL Server) | Microsoft Docs SQL For XML 参见:FOR XML (SQL Server) | Microsoft Doc ...
- 大数据框架:Spark vs Hadoop vs Storm
大数据时代,TB级甚至PB级数据已经超过单机尺度的数据处理,分布式处理系统应运而生. 知识预热 「专治不明觉厉」之“大数据”: 大数据生态圈及其技术栈: 关于大数据的四大特征(4V) 海量的数据规模( ...
- PHP初步:在Mac OS X Yosemite下搭建Apache+PHP+Mysql
Mac OS X是基于unix的操作系统,很多软件都集成在系统中.所以,对于配置PHP的开发环境相对于windows和Linux更简单. 1. 启动Apache服务器 打开终端(terminal),查 ...