(两头堵)去除两边空格
来源:互联网 发布:猫和平相处 知乎 编辑:程序博客网 时间:2024/04/28 22:52
#define _CRT_SECURE_NO_WARNINGS#include <stdio.h>#include <stdlib.h>#include <string.h>void trimSpace(char **str){if (str == NULL){return;}char *tmp = *str;if (tmp == NULL){return;}char *left = tmp;char *right = tmp + strlen(tmp) - 1;while (*left == ' '){left++;}while (*right == ' ' && right != tmp){right--;}if (right - left + 1 <= 0){*str = NULL;return;;}if (*(right + 1) != '\0'){*(right + 1) = '\0';}*str = left;}int count_space(char *str){if (NULL == str){return -1;}char *left = str;char *right = str + strlen(str) - 1;while (*left == ' '){left++;}while (*right == ' ' && right != str){right--;}if (right - left + 1 < 0){return 0;}return right - left + 1;}void test(){char *str = (char *)malloc(100);if (str == NULL){return;}memset(str, 0, 100);strcpy(str, " dsss ");int count = 0;count = count_space(str);trimSpace(&str);printf("%d\n", count);if (str == NULL){printf("内容为空\n");}else{printf("%s\n", str);}}void main(){test();system("pause");}
0 0
- (两头堵)去除两边空格
- C语言两头堵模型(去两头空格)
- 字符串两头堵的模型就是去掉两边空格,已经字符串1,在字符串2出现的次数,不修改输入。
- JS去除两边空格
- javascript去除两边空格
- Oracle 去除两边空格
- Oracle 去除两边空格
- 去除字符串两边空格
- javascript去除左右两边空格
- JavaScript去除字符串两边空格
- 去除字符串两边空格源码
- 两头堵模型
- 两头堵模型
- C字符串操作:两头堵实现trim()
- 笔试题:去除字符串两头空格,合并中间空格
- 统计字符串中非空格字符串的长度并取出--两头堵模型
- NSString去除两边空格字符,like trim()
- JavaScript去除字符串两边空格trim
- Java集合---ArrayList的实现原理
- FAT32文件
- [LeetCode]--190. Reverse Bits(不是很懂的位运算)
- oracle一个事务的完整流程分析
- windows下MySQL忘记密码解决方法(5.7版本)
- (两头堵)去除两边空格
- windbg的命令备忘录
- git详解(一)git的介绍与基本设置
- 【资源汇总】OpenGL
- Linux内核:通过wait_event和wake_up内在机制分析等待队列
- Jquery小点滴 - 获取和设置元素value属性
- 【Thinking in Java】复用类
- Java面试题之SSH框架
- 输入一个0~6的整数,换成星期输出