strcspn
来源:互联网 发布:list找出重复数据 编辑:程序博客网 时间:2024/06/05 20:14
头文件:#inclued<string.h>
strcspn()用来检索字符串s1开头连续有几个字符都不含字符串s2中的字符,其原型为:
int strcspn(char *s1, char *s2);
【参数说明】s1、s2为要进行查找的两个字符串。
strcspn()从字符串s的开头计算连续的字符,而这些字符都完全不在字符串s2中。简单地说,若strcspn()返回的数值为n,则代表字符串s1开头连续有n 个字符都不含字符串s2中的字符。
【返回值】返回字符串s1开头连续不含字符串s2内的字符数目。
注意:strcspn()会检查字符串结束标志'\0';如果s1中的字符都没有在s2中出现,那么将返回s1的长度;检索的字符是区分大小写的。
【函数示例】返回s1、s2包含的相同字符串的位置。
再看一个例子,判断两个字符串的字符是否有重复的。
strcspn()用来检索字符串s1开头连续有几个字符都不含字符串s2中的字符,其原型为:
int strcspn(char *s1, char *s2);
【参数说明】s1、s2为要进行查找的两个字符串。
strcspn()从字符串s的开头计算连续的字符,而这些字符都完全不在字符串s2中。简单地说,若strcspn()返回的数值为n,则代表字符串s1开头连续有n 个字符都不含字符串s2中的字符。
【返回值】返回字符串s1开头连续不含字符串s2内的字符数目。
注意:strcspn()会检查字符串结束标志'\0';如果s1中的字符都没有在s2中出现,那么将返回s1的长度;检索的字符是区分大小写的。
【函数示例】返回s1、s2包含的相同字符串的位置。
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char* s1 = "http://see.xidian.edu.cn/cpp/u/biaozhunku/";
- char* s2 = "c is good";
- int n = strcspn(s1,s2);
- printf("The first char both in s1 and s2 is :%c\n",s1[n]);
- printf("The position in s1 is: %d\n",n);
- return 0;
- }
#include<stdio.h>#include<string.h>int main(){ char* s1 = "http://see.xidian.edu.cn/cpp/u/biaozhunku/"; char* s2 = "c is good"; int n = strcspn(s1,s2); printf("The first char both in s1 and s2 is :%c\n",s1[n]); printf("The position in s1 is: %d\n",n); return 0;}
再看一个例子,判断两个字符串的字符是否有重复的。
- #include<stdio.h>
- #include<string.h>
- int main()
- {
- char* s1 = "http://see.xidian.edu.cn/cpp/xitong/";
- char* s2 = "z -+*";
- if(strlen(s1) == strcspn(s1,s2)){
- printf("s1 is diffrent from s2!\n");
- }else{
- printf("There is at least one same character in s1 and s2!\n");
- }
- return 0;
- }
0 0
- strcspn
- strcspn
- strcspn函数
- strcspn() 函数
- strcspn () 函数
- strcspn函数
- strcspn函数
- strcspn函数
- strcspn函数
- strspn & strcspn
- strspn和strcspn妙用
- strspn和strcspn妙用
- strcspn的用法
- strspn strcspn 函数
- strcspn源码分析
- strspn() and strcspn()
- strpbrk和strcspn用法
- strspn和strcspn
- Linux 内核驱动固件加载方式
- strchr
- Thinkphp生成静态页面
- 关于Git的一点学习(一)
- 优秀前端学习资源汇总
- strcspn
- django 模板 html 分段输出
- windows安装tomcat服务
- 二维码在线生成 和 在线格式化工具
- 后端技术流博客收藏
- strcpy
- 学习SpringMVC系列教程(一)Spring MVC入门
- 展望未来,总结过去10年的程序员生涯,给程序员小弟弟小妹妹们的一些总结性忠告
- win7实现多用户同时远程登录到PC端