CString中空格的删除问题.

pqxx 2002-04-08 07:30:15
我用CString读取文本文件中的数据,连同分隔用的
空格一起读了下来,在字符转换中需要将其剔除,
空格不仅存在于CSting的头尾中间有时也存在空格,
那位大哥如果作过的话,还望赐教.
...全文
469 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
pqxx 2002-04-09
  • 打赏
  • 举报
回复
不好意思啊!我这里上网不太方便,几个人轮流用这台能上网的
机子,如果那位觉得给分晚了的话,还请多多包含。
问题已经解决谢谢大家的帮助。
dishou 2002-04-08
  • 打赏
  • 举报
回复
CString str;
str.TrimLeft();//去掉str左边空格
str.TrimRight();//去掉str右边空格
int Space_pos=0;
while(Space_pos>=0)
{
Space_pos=str.Find(" ");
str.Delete(pos,1);//Delete函数大致是这样用的,如不对你可自己查MSDN
}
我的程序是这么用的, 好用.
地平线 2002-04-08
  • 打赏
  • 举报
回复

strText.Replace(_T(" "),NULL);
hnyyy 2002-04-08
  • 打赏
  • 举报
回复
str.Remove(' ');
ruixp 2002-04-08
  • 打赏
  • 举报
回复
同意头上两位的
aileen_long 2002-04-08
  • 打赏
  • 举报
回复
CString strTmp = "Remove all blank!"
strTmp.Remove(' '); // 去掉所有的空格。不知道是不是你想要的
pandalittle 2002-04-08
  • 打赏
  • 举报
回复
很简单,以下是我的代码,要给分哦
CString strTest;
CStringArray straTest;
strTest="This is a test String";
int nStart=0;
int nEnd =0;
BOOL bInWord=FALSE;
int nLength=strTest.GetLength ();
while(nStart<nLength)
{
nEnd = strTest.Find(" ",nStart);
if (nEnd==-1) nEnd=nLength;
if(nEnd!=nStart)
{
straTest.Add (strTest.Mid (nStart,nEnd-nStart));
}
nStart=nEnd+1;
}
int nCount=straTest.GetSize ();
for(int i=0;i<nCount;i++)
{
MessageBox(straTest.GetAt (i));
}
quengzi 2002-04-08
  • 打赏
  • 举报
回复
CSting str = "test test test";
int madk = str.Find("\b");//好象是\b,你查msdn
CString strTemp;
strTemp = str.Mid(0,mask);
str.Right(str.Getlength() - mask);
.....
你自己设计个循环吧。
GZCompiler 2002-04-08
  • 打赏
  • 举报
回复
...
CString str=" this is a test ! ";
char *str1=str.GetBuffer[20];
char *p=str1;
char result[20]; //结果字符串

int i=0;
while(*p!='\0')
{
if(*p!=' ')
{
result[i]=*p;
i++;
}
p++;
}
result[i]='\0';
cout<<result<<endl;

...
meat 2002-04-08
  • 打赏
  • 举报
回复
做一个循环判断
sarage 2002-04-08
  • 打赏
  • 举报
回复
我记得有一个函数是叫什么trim吧(年代久远,记不清楚了),你试试。

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • AIGC Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧