有关字符串的三种操作
来源:互联网 发布:网络大白兔是什么意思 编辑:程序博客网 时间:2024/06/06 00:50
去掉字符串两端空格
int trimSpace(const char *inbuf, char *outbuf){ int count = 0; int i = 0, j = 0; char *p = inbuf; j = strlen(p) -1; if(NULL==inbuf || NULL==outbuf) { printf("NULL==inbuf || NULL==outbuf err\n"); return -1; } while (isspace(p[i]) && p[i] != '\0')//从前往后 { i++; } while (isspace(p[j]) && j>0)//从后往前 { j--; } count = j-i +1; printf("除去空格有%d个字符\n", count); //将从p1往后的size_t个字符拷贝到p中 memcpy(outbuf, inbuf+i, count); outbuf[count] = '\0'; return 0;}
字符串反转
//int str_fz(char *str){ char *p1,*p2; char c; int reg=0; if(NULL==str) { reg=-1; printf("str_fz(NULL==str):%d\n",reg); return reg; } p1=str; p2=p1+strlen(str)-1; while(p1<p2) { c=*p2; *p2=*p1; *p1=c; p1++; p2--; } return reg; }
计算一个字符串中子字符串个数
//int CalcStr1_to_str2(char *str1,char *str2,int *mycount){ int count=0; char *p=str1; if(NULL==str1||NULL==str2||NULL==mycount) { printf("CalcStr1_to_str2 err\n"); return -1; } while(*p!='\0') { p=strstr(p,str2); if(p!=NULL) { count++; p=p+strlen(str2); } else { break; } } *mycount=count; return 0;}
阅读全文
0 0
- 有关字符串的三种操作
- 有关字符串的操作
- 有关字符串的一些操作
- 有关oracle数据库的三种不同操作
- symbian中的字符串操作的有关方法
- 有关String 字符串的各种操作大全
- Lua中有关字符串的进阶操作
- js 中有关字符串的操作
- 树的有关操作 (三)
- 字符串有关操作函数
- 字符串的操作 练习三
- 有关UNICODE、ANSI字符集和相关字符串操作的总结!
- 有关UNICODE、ANSI字符集和相关字符串操作的总结
- 有关UNICODE、ANSI字符集和相关字符串操作的总结!
- 有关UNICODE、ANSI字符集和相关字符串操作的总结
- 有关UNICODE、ANSI字符集和相关字符串操作的总结!
- 有关UNICODE、ANSI字符集和相关字符串操作的总结!
- 有关UNICODE、ANSI字符集和相关字符串操作的总结
- leetcode 729与731. My Calendar II的通用解题思路
- jni静态实现方法
- jQuery批量非空校验
- 后端开发--基础概念:Session 与 Cookie 的比较(1)
- 用Nikto探测一个网站安全性
- 有关字符串的三种操作
- 农夫与牛问题的分析 ---二分法流弊
- Tomcat服务器配置https双向认证(使用keytool生成证书)
- Linux中常用的50个命令
- HDUOJ 1087
- ICE简单介绍及使用示例
- vue 的局部组件
- 【Tensorflow slim】slim evaluation 函数
- 封装jquery之ajax