- 论坛徽章:
- 0
|
想删除一个string中的所有大于两格的空格字串
- #include <stdio.h>;
- #include <stdlib.h>;
- #include <string.h>;
- ///////////////////////////////////////////////////////////////////////////////
- // 功能说明 : 过滤字符串中多个空格 转成一个空格
- // 输入参数 : szBuff
- // : nLen
- // 输出参数 : nLen
- // 返回值 : void
- // 使用说明 :
- ///////////////////////////////////////////////////////////////////////////////
- void FilterBuffer(char *szBuff, int &nLen)
- {
- int Count = 0;
- unsigned char ch = 0;
-
- for(int i = 0; i < nLen; i ++)
- {
- ch = ( unsigned char )szBuff[i];
- if ( (ch == ' ')
- && ( szBuff[i+1] == ' ' ) )
- continue;
- else
- szBuff[Count ++] = szBuff[i];
- }
-
- nLen = Count;
- szBuff[nLen] = '\0';
- }
- int main ( int argc, char*argv[] )
- {
- char sz[20+1] = "ff ff ff";
- int len = strlen(sz);
- FilterBuffer( sz, len );
- printf ( "%s", sz );
- return 0;
- }
复制代码
仓促改了个,你自己改进看看. |
|