删除字符串右边的全部空格
2012-05-09 19:48
295 查看
#include <iostream> using namespace std; //删除字符串右边的全部空格 char *my_trim( char *str ) { if (NULL == str) { throw; } char *const address = str; const int ONE_ELEMENT = 1; const char NULL_TERMINATED = '\0'; while (NULL_TERMINATED != *str) { ++str; } while (address != str && isspace( *(str - ONE_ELEMENT) )) { --str; } *str = NULL_TERMINATED; str = address; return str; } int main(int argc,char*argv[]) { char buf[] = "ok2002.com "; cout << strlen( buf ) << endl; my_trim( buf ); cout << strlen( buf ) << endl; system( "PAUSE" ); return EXIT_SUCCESS; } /*---- 24 10 请按任意键继续. . . -----------------------*/
相关文章推荐
- 【字符串】删除多余的空格
- 16周,指针字符串处理,删除空格
- jQuery的$.trim函数可以删除字符串前后的换页、换行、制表、回车、空格、垂直制表等字符。
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个。
- php删除字符串中的所有空格
- 删除字符串中的空格
- 如何删除字符串中多余的空格
- 正则表达式_删除字符串中的任意空格(Regex)
- 常见C语言面试题之四:删除字符串头尾空格,字符串右对齐
- javascript中删除字符串空格的方法
- Perl中删除或替换字符串中特殊字符(如空格)的方法
- php删除字符串中的所有空格
- PHP学习笔记--字符串操作 作者:yezi33 字符串的整理: trim():除去字符串开头和末尾的空格或其他字符。函数执行成功时返回删除了string字符串首部和尾部空格的字符串,发生错误时返回空
- 删除字符串开始和结尾空格,并将中间多个空格合并为一个空格
- js去掉字符串全部空格
- 给定字符串,删除开始和结尾处的空格,并将中间的多个连续的空格合并成一个
- 删除字符串开始及末尾的空白符,并且把数组中间的多个空格(如果有)符转化为1个
- 删除字符串中的空格
- c语言字符串-常用操作(3)删除空格
- JavaScript删除字符串中的空格