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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。