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 ...
随机推荐
- DbSet中Find,AsNoTracking,Attach及DBEntityEntry,ChangeTracker
Find,AsNoTracking,Attach,DBEntityEntry,ChangeTracker,Local 一:DBSet 我们在SaveChange的时候,如果获取到DbSet中一些Ent ...
- vmware开发包之vSphere Management SDK
vSphere Management SDK关于vmware管理等相关功能的.net和java的代码示例. 在其5.5的解压包中 eam:esx agent management表示esx虚机生产环境 ...
- Ubuntu sudo apt-get update提示 Failed to fetch,解决办法
问题: 执行sudo apt-get update提示:Failed to fetch chen@ubuntu:~/soft/Python-$ sudo apt-get update Get: htt ...
- 使用PLSQL Developer时中文乱码问题
使用PLSQL Developer时中文乱码问题 一.问题: 执行一些查询结果有中文的SQL语句,显示不了中文,显示???. 二.产生的原因: 客户端与服务器端的编码不一致造成的. 三.解决方案: 1 ...
- leetcode 55. 跳跃游戏 JAVA
题目: 给定一个非负整数数组,你最初位于数组的第一个位置. 数组中的每个元素代表你在该位置可以跳跃的最大长度. 判断你是否能够到达最后一个位置. 示例 1: 输入: [2,3,1,1,4] 输出: t ...
- luoguP2479 [SDOI2010]捉迷藏
https://www.luogu.org/problemnew/show/P2479 据说可以用线段树做但是我不会,只能写一个 KD-Tree 了 对于每个点求出距离它最远的点和最近的点的距离,然后 ...
- BZOJ3531-[Sdoi2014]旅行(树剖+线段树动态开点)
传送门 完了今天才知道原来线段树的动态开点和主席树是不一样的啊 我们先考虑没有宗教信仰的限制,那么就是一个很明显的树剖+线段树,路径查询最大值以及路径和 然后有了宗教信仰的限制该怎么做呢? 先考虑暴力 ...
- python 注释 与 windows 上用tab 自动补齐设置
python的注释 单行注释:用# 多行代码用:“”“ 中间为你要注释的解释 ”“” # 我是单行注释 我是一个#号 print("hello,word") "&quo ...
- 关于:maven项目中pom.xml文件添加依赖无法自动搜索的问题
用的是eclipse 1.Window------>Show View------->Maven Repositories(这个选项一般不直接显示,而在others里面) 2.操作完毕后会 ...
- PyQt5(5)——加载资源文件
在实际中我们需要美化界面,就需要许多的自定义图片. 但是我们发现直接导入图像使用,等程序运行时会报错.???? 这就需要建立资源文件并且加载它们,程序就可以顺利运行了. 设计界面是如何加载资源文件呢? ...