标题: BC++ 3 如何去除 前后空格
[打印本页]
作者: app1
时间: 2009-4-30 22:56
标题: BC++ 3 如何去除 前后空格
char *sp=" GUI$ Y ";
我想把以上的文本 前后空格去除掉
变成
GUI$ Y
然后 替换 $ 为 .
GUI.Y
查了好久 不知道怎么处理
char *pp=sp.erase(0,sp.find_not_of(" "));
以上用 删除(erase) 函数
报错 Structure required on left side of . or *
作者: app1
时间: 2009-4-30 23:04
Borland C++ 3 请问各位有没有什么好的 教程阿
作者: winson4829
时间: 2009-5-11 10:30
int MyTrim(char *ss)
{
char *head,*tail;
char *ts;
head=ss; // 指向字串的最前
tail=ss+(strlen(ss)-1); // 指向字串的最後
while(tail>=head) // 清除字串之後的空白
{
if(*tail==' ' || *tail==0x0a || *tail==0x0d) *tail--='\0'; else break;
}
while(*head!='\0') // 清除字串之前的空白
{
if(*head==' ') head++; else break;
}
ts =ss;
while(*head!='\0') *ts++=*head++;
*ts='\0';
while(ts<=tail) *ts++='\0'; // 之後的字元全部補NULL
if(*ss=='\0') return(0); else return(1);
}