Solved

HOW to Remove Blanks from CString.

Posted on 2000-05-15
6
449 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 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 20 total points
ID: 2811233
Might be cleaner to say:

CString str = "hello world";
str.TrimLeft();
str.TrimRight();
TextOut(...,str);
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Replacement selected text 2 63
How to determine file rename from EventLog ? 2 55
method notes when mouse over in eclipse 5 87
wordcount challenge 11 134
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…
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.

821 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