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 ...
随机推荐
- Application.DoEvent和定时刷新控件
我们写一个textbox,让其依循环递增,但每次都会出现假死现象,等循环结束后,变为最终值.今天总结一下: private void button3_Click(object sender, Even ...
- Android-相对布局(RelativeLayout)
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android=&qu ...
- HBase介绍(2)---数据存储结构
在本文中的HBase术语:基于列:column-oriented行:row列组:column families列:column单元:cell 理解HBase(一个开源的Google的BigTable实 ...
- EF修改model自动更新数据库
最近用MVC+EF学习时遇到修改model后而数据库没更新报错,就在网上找关于数据迁移自动更新数据库的,折腾了大半天终于弄了出来 第一步:在程序包管理器控制台里: Enable-Migrations ...
- Web.config配置文件详解(新手必看) (转载)
原文地址:http://www.cnblogs.com/gaoweipeng/archive/2009/05/17/1458762.html <?xmlversion="1.0&quo ...
- Mvc 项目中使用Bootstrap以及基于bootstrap的 Bootgrid
官方地址参考http://www.jquery-bootgrid.com/Examples Bootgrid 是一款基于BootStrap 开发的带有查询,分页功能的列表显示组件.可以在像MVC中开发 ...
- RHEL因为selinux设置失误,无法重启问题。(centos适用)
今天做FTP模拟的时候selinux设置出现失误.导致系统无法重新启动.出现如下界面 Failed To Load SELinux policy.freezing .. 网上找了下,解决方法如下: 开 ...
- codeVS 动态最大子段和
题目链接:戳我 对于最大子段和,我们只需要维护四个变量--maxl,maxr,maxs,sum(分别表示区间最大前缀子段和,区间最大后缀子段和,区间最大子段和,区间所有数的和) 然后合并的时候是这样的 ...
- Pycharm中安装Pygame并写第一个程序
第一步:打开Pycharm 第二步:点File ->Default Settings->Project Interpreter->点加号 第三步: 搜索Pygame->Inst ...
- windbg 常用命令详解
= kd> ln 8046e100 (8046e100) nt!KeServiceDescriptorTableShadow | (8046e140) nt!MmSectionExtendRes ...