当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


C语言 strspn()用法及代码示例


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


相关用法


注:本文由纯净天空筛选整理自 strspn() function in C。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。