Solved

HOW to Remove Blanks from CString.

Posted on 2000-05-15
6
446 Views
Last Modified: 2013-11-20
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?

0
Comment
Question by:mkjoshi
6 Comments
 
LVL 8

Expert Comment

by:VinExpert
ID: 2810838
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
 
LVL 30

Expert Comment

by:Zoppo
ID: 2810872
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
 
LVL 4

Accepted Solution

by:
captainkirk earned 20 total points
ID: 2811233
Might be cleaner to say:

CString str = "hello world";
str.TrimLeft();
str.TrimRight();
TextOut(...,str);
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 23

Expert Comment

by:chensu
ID: 2811243
The memory size allocated for STR is not enough. Make sure it can contain the string after strcat.
0
 
LVL 1

Expert Comment

by:ch_vasu
ID: 2812961
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
 

Author Comment

by:mkjoshi
ID: 2813077
It really solved my problem,
Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Change owner from userA to server Local Administrators 7 51
sum28 challenge 31 96
has77  challenge 9 67
Detect file exist or not 3 77
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now