strcspn

来源:互联网 发布:孙俪的等花开淘宝 编辑:程序博客网 时间:2024/05/21 14:58

原型

size_t strcspn(const char *s, const char * reject);


功能

若strcspn()返回的数值为n, 则代表字符串s 连续有n 个字符不含字符串reject 内的字符.


示例

#include <string.h>#include <iostream.h>void main(){    char *s="Golden Global View";    cout<<strcspn(s, " ")<<endl;    cout<<strcspn(s, "Hell")<<endl;    cout<<strcspn(s, "World")<<endl;    cout<<strcspn(s, "mkt")<<endl;}



结果:
6 //返回空格之前的位数
2 //返回l之前的位数
1 //返回o之前的位数

18 //没有找到任何一个字符,返回整个字符串长度



0 0