strcspn
原型:size_t strcspn(const char *s1,const char *s2);
相关头文件:#include <string.h>
功能:在字符串s1中搜寻s2中所出现的字符,返回s2中出现的第一个字符在S1中出现的位置。
说明:(返回第一个出现的字符在s1中的下标值,亦即在s1中出现而s2中没有出现的子串的长度。)
简单地说,若strcspn()返回的数值为n,则代表字符串s开头连续有n个字符都不含字符串reject内的字符。
举例:
// strcspn.c
#include <stdio.h >
#include <syslib.h>
#include <string.h>
int main(void)
{
char *s="Golden Global View";
char *r="new";
int n;
clrscr();
n=strcspn(s,r);
printf("The first char both in s1 and s2 is: %c",s[n]);
getchar();
return 0;
}