C string strspn() 函数
定义和用法
strspn() 函数在字符串中搜索第一个不匹配指定字符集中任何字符的字符,并返回字符串到该位置的长度。
strspn() 函数定义在 <string.h> 头文件中。
实例
测量字符串到第一个非数字字符的长度:
char myStr[] = "4096 bytes should be enough";
int pos = strspn(myStr, "0123456789");
printf("%d", pos);
语法
strspn(void * str, void * search);
参数
| 参数 | 描述 |
|---|---|
| str | 必需。要搜索的字符串。 |
| search | 必需。包含要搜索的字符集的字符串。 |
技术细节
| 返回: | 返回整数,指示第一个不匹配搜索字符集中任何字符的字符的位置(以字符数计)。 |
|---|
相关页面
教程:C 字符串
教程:C 字符串函数