名稱空間
變體
操作

strspn

來自 cppreference.com
< c‎ | string‎ | byte
定義於標頭檔案 <string.h>
size_t strspn( const char* dest, const char* src );

返回指向 dest 的空終止位元組字串的最大初始段(跨度)的長度,該初始段僅由指向 src 的空終止位元組字串中找到的字元組成。

如果 destsrc 不是指向空終止位元組字串的指標,則行為未定義。

目錄

[編輯] 引數

dest - 指向要分析的以空字元結尾的位元組字串的指標
src - 指向包含要搜尋的字元的以空字元結尾的位元組字串的指標

[編輯] 返回值

最大初始段的長度,該初始段僅包含來自指向 src 的空終止位元組字串的字元。

[編輯] 示例

#include <stdio.h>
#include <string.h>
 
int main(void)
{
    const char* string = "abcde312$#@";
    const char* low_alpha = "qwertyuiopasdfghjklzxcvbnm";
 
    size_t spnsz = strspn(string, low_alpha);
    printf("After skipping initial lowercase letters from '%s'\n"
           "The remainder is '%s'\n", string, string + spnsz);
}

輸出

After skipping initial lowercase letters from 'abcde312$#@'
The remainder is '312$#@'

[編輯] 參考資料

  • C23 標準 (ISO/IEC 9899:2024)
  • 7.24.5.6 strspn 函式 (p: TBD)
  • C17 標準 (ISO/IEC 9899:2018)
  • 7.24.5.6 strspn 函式 (p: TBD)
  • C11 標準 (ISO/IEC 9899:2011)
  • 7.24.5.6 strspn 函式 (p: 369)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.21.5.6 strspn 函式 (p: 332)
  • C89/C90 標準 (ISO/IEC 9899:1990)
  • 4.11.5.6 strspn 函式

[編輯] 另請參閱

返回由另一個位元組字串中找到的字元組成的最大初始段的長度
僅由另一個位元組字串中未找到的字元組成
(函式) [編輯]
(C95)
返回由另一個位元組字串中找到的字元組成的最大初始段的長度
僅包含在另一個寬字串中找到的寬字元
(函式) [編輯]
在一個字串中查詢另一個字串中任意字元的第一個位置
(函式) [編輯]