?
Solved

HOW to Remove Blanks from CString.

Posted on 2000-05-15
6
Medium Priority
?
458 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 31

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 80 total points
ID: 2811233
Might be cleaner to say:

CString str = "hello world";
str.TrimLeft();
str.TrimRight();
TextOut(...,str);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

719 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