strspn()函數返回str1指向的字符串的初始子字符串的長度,該字符串僅由str2指向的字符串中包含的那些字符組成。
用法:
size_t strspn(const char *str1, const char *str2) str1: string to be scanned. str2: string containing the characters to match. 返回值: This function returns the number of characters in the initial segment of str1 which consist only of characters from str2.
// C program to illustrate strspn() function
#include <stdio.h>
#include <string.h>
int main () {
int len = strspn("geeks for geeks","geek");
printf("Length of initial segment matching:%d\n", len );
return(0);
}
輸出:
Length of initial segment matching 4
// C program to illustrate strspn() function
#include <stdio.h>
#include <string.h>
int main () {
int len = strspn("i am","xyz");
printf("Length of initial segment matching:%d\n", len );
return(0);
}
輸出:
Length of initial segment matching 0
相關用法
- C語言 tolower()用法及代碼示例
- C語言 strlwr()用法及代碼示例
- C語言 putchar()用法及代碼示例
- C++ iswblank()用法及代碼示例
- C++ wcstoll()用法及代碼示例
- C++ ldexp()用法及代碼示例
- C++ iswalnum()用法及代碼示例
- C++ raise()用法及代碼示例
- C++ feupdateenv()用法及代碼示例
- C++ exp2()用法及代碼示例
- C++ gmtime()用法及代碼示例
- C++ iswpunct()用法及代碼示例
- C++ towupper()用法及代碼示例
注:本文由純淨天空篩選整理自 strspn() function in C。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。