• C 标准库


    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
    ", (unsigned int) len); //4
        len = strspn(str1, str3);
        printf("%d
    ", (unsigned int) len); //0
        len = strspn(str1, str4);
        printf("%d
    ", (unsigned int) len); //2
        len = strspn(str1, str5);
        printf("%d
    ", (unsigned int) len); //1
        len = strspn(str1, str6);
        printf("%d
    ", (unsigned int) len); //0
    
        char strtext[] = "129th";
        char cset[] = "1234567890";
    
        len = strspn(strtext, cset);
        printf("The initial number has %d digits.
    ", (int) len);//3
    
        const char *string = "abcde312$#@";
        const char *low_alpha = "qwertyuiopasdfghjklzxcvbnm";
    
        len = strspn(string, low_alpha);
        printf("%d
    ",(int)len);//5
        //After skipping initial lowercase letters from 'abcde312$#@'
        printf("After skipping initial lowercase letters from '%s'
    "
                   "The remainder is '%s'
    ", string, string + len);//The remainder is '312$#@'
    
        return (0);
    }
    

    参考文章

    转载注明出处

  • 相关阅读:
    UI21-多线程: GCD Grand Center Dispatch
    UI20- CollectionView瀑布流
    UI19-数据库操作:CoreDtata
    UI18-数据库操作:SQL FMDB
    UI17-数据库操作:SQLite
    UI16-通过Xcode将代码提交到github上, 把仓库放在github上
    UI15-存储路径
    UI14-沙盒机制,文件的读写,文件管理器的增删移动复制,归档和反归档。
    UI13-异步下载图片
    数据库相关中间件介绍
  • 原文地址:https://www.cnblogs.com/zhangrxiang/p/8419492.html
Copyright © 2020-2023  润新知