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);
}

参考文章

转载注明出处

C 标准库 - string.h之strspn使用的更多相关文章

  1. C 标准库 - string.h

    C 标准库 - string.h This header file defines several functions to manipulate C strings and arrays. stri ...

  2. C标准库<string.h>实现

    本文地址:http://www.cnblogs.com/archimedes/p/c-library-string.html,转载请注明源地址. 1.背景知识 <string.h>中声明的 ...

  3. C 标准库 - string.h之strpbrk使用

    strpbrk Locate characters in string,Returns a pointer to the first occurrence in str1 of any of the ...

  4. C标准库string.h中几个常用函数的使用详解

    strlen 计算字符串长度 size_t strlen(const char *str) 计算字符串 str 的长度,直到空结束字符,但不包括空结束字符. 函数实现: int Strlen(cons ...

  5. C 标准库 - string.h之memmove使用

    memmove Move block of memory Copies the values of num bytes from the location pointed by source to t ...

  6. C 标准库 - string.h之memcpy使用

    memcpy Copy block of memory Copies the values of num bytes from the location pointed to by source di ...

  7. C 标准库 - string.h之memcmp使用

    memcmp Compare two blocks of memory. Compares the first num bytes of the block of memory pointed by ...

  8. C 标准库 - string.h之memchr使用

    memchr Locate character in block of memory,Searches within the first num bytes of the block of memor ...

  9. C 标准库 - string.h之strlen使用

    strlen Returns the length of the C string str. The length of a C string is determined by the termina ...

随机推荐

  1. 【C#】泛型

    泛型是一个非常有用的技术,在博客园里面有太多说到泛型的好文章,这里我推荐一篇我个人觉得非常全面,也非常齐全的文章. (重造轮子很傻!!!) C# -- 泛型(1) C# -- 泛型(2) C# -- ...

  2. Replication--发布属性immediate_sync

    在创建发布时,如果选择立即初始化,会将immediate_sync属性设置为true.如果immediate_sync属性为true时,snapshot文件和发布事务及发布命令将一直保留到指定的事务保 ...

  3. thinkphp多级分类

    核心代码类(放在了Common下的Common文件夹下): namespace Common\Common; class Tool { static public $treeList = array( ...

  4. SpringBoot入门(三)——入口类解析

    本文来自网易云社区 上一篇介绍了起步依赖,这篇我们先来看下SpringBoot项目是如何启动的. 入口类 再次观察工程的Maven配置文件,可以看到工程的默认打包方式是jar格式的. <pack ...

  5. HAOI2010 最长公共子序列

    题目链接:戳我 30分暴力....暴力提取子序列即可qwqwq #include<iostream> #include<cstdio> #include<algorith ...

  6. 关于C# 向TIM或者QQ自动发送中文消息【微信也是可用的】 附测试GIF中微信可用的 全新修订

    在上一篇文章的代码 对于微信已失效 重新更新一边 效果图: 源代码 using System; using System.Runtime.InteropServices; using System.T ...

  7. eclipse问题 - windows版

    问题:java compiler level does not match the version of the installed java project facet:但是项目仍能运行 解释:项目 ...

  8. 初学python - 使用pip安装扩展库

    cmd pip install -i https://pypi.tuna.tsinghua.edu.cn/simple PyMySQL - 使用清华镜像下载PyMySQL pip python包管理工 ...

  9. 洛谷P3706 [SDOI2017]硬币游戏(概率生成函数+高斯消元)

    题面 传送门 题解 不知道概率生成函数是什么的可以看看这篇文章,题解也在里面了 //minamoto #include<bits/stdc++.h> #define R register ...

  10. c语言-折半查找的函数

    void search(int n,int num[],char name[N][10]) { int top,bottom,middle,location,flag; top=0; bottom=N ...