C中的strspn()函数

这个 strspn() 函数返回所指向字符串的初始子字符串的长度 str1 它只由所指向的字符串中包含的字符组成 str2 .

null

语法:

size_t strspn(const char *str1, const char *str2)
str1 : string to be scanned.
str2 : string containing the 
characters to match.
Return Value : 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" , 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" , len );
return (0);
}


输出:

Length of initial segment matching 0

本文由 希瓦尼·古泰尔 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享