📜  C语言中的strspn()函数

📅  最后修改于: 2021-05-26 02:06:23             🧑  作者: Mango

strspn()函数返回str1指向的字符串的初始子字符串的长度,该字符串仅由str2指向的字符串包含的那些字符。

句法 :

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 
#include 
  
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 
#include 
  
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的C基础课程》。