C 字符串 strcspn() 函数
示例
Measure the length of the string up to the first punctuation mark:
char myStr[] = "Learn C++, Java and Python!";
int pos = strcspn(myStr, ",.!?");
printf("%d", pos);
亲自试一试 »
定义和用法
strcspn() 函数在字符串中查找指定字符的首次出现,并返回字符串到该点的长度。 If none of the characters are found then the length of the string is returned.
strcspn() 函数定义在 <string.h> 头文件中。
语法
strcspn(void * str, void * search);
参数值
| 参数 | 描述 |
|---|---|
| str | 必需。要搜索的字符串。 |
| search | 必需。要搜索的字符集字符串。 |
技术细节
| 返回值: | 一个整数,表示搜索字符首次出现的位置;如果未找到任何字符,则表示字符串的长度。 |
|---|

