C 程式設計/string.h/strcspn
外觀
strcspn 是 C 標準庫中的函式 (標頭檔案 string.h)。
它搜尋字串中是否存在某組字元。
strcspn() 函式計算字串 1 的初始段的長度,該段不包含字串 2 中的任何字元。
此函式返回字串 1 中第一個與字串 2 中任何字元匹配的字元的索引。
#include <string.h>
size_t strcspn( const char *str1, const char *str2 );
#include <stdio.h>
#include <string.h>
int main(){
char s[20] = "wikireader007", t[11] = "0123456789";
printf("The first decimal digit of s is at position: %d.\n", '''strcspn'''(s, t));
return 0;
}
輸出:
s 中的第一個十進位制數字位於位置:10