HOW to Remove Blanks from CString.

HI,
  i HAVE
 CString str;
 char STR [10]="hello world";
  strcat(STR,str);


later I have TEXTOUT(.....,STR);
It works fine, But STR contains some blank sapces at the end of the text. How di I remove them before printing?

mkjoshiAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
captainkirkConnect With a Mentor Commented:
Might be cleaner to say:

CString str = "hello world";
str.TrimLeft();
str.TrimRight();
TextOut(...,str);
0
 
Vinayak KumbarSr Program ManagerCommented:
Hi,

How about doing like this.

CString str;
char STR [10]="hello world";
str += STR;

//From where blanks came!!!?
str.TrimLeft();
str.TrimRight();

Then
TextOut(..., str);

Try it out.

VinExpert
0
 
ZoppoCommented:
Hi mkjoshi,

caution:
STR is defined in your code as a pointer to an array of 10 chars. "Hello world" needs an array of at least 12 chars (including the terminating zero).

char STR[12] = "hello world";

should solve the problem here.

It's just luck that the code doesn't crash...

ZOPPO
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
chensuCommented:
The memory size allocated for STR is not enough. Make sure it can contain the string after strcat.
0
 
ch_vasuCommented:
Hi,
Replace your code with this code and try out. This code should work

CString str;
char STR [100]="hello world";//Increase the size
CString strTemp;
strTemp.Format("%s%s",STR,str);//Append the string
strTemp.TrimLeft();//Remove space
strTemp.TrimRight();//Remove space
TextOut(...,strTemp.GetBuffer(0));

Vasudev
0
 
mkjoshiAuthor Commented:
It really solved my problem,
Thanks.
0
All Courses

From novice to tech pro — start learning today.