Solved

concatenation of 2 strings

Posted on 2000-03-19
6
186 Views
Last Modified: 2013-11-20
I have 2 strings:
CString str1 = "123                     ";
Cstring str2 = "789011";
when I use: CString str3 = str1.Left(7) + str2.Left(6);
I get: "123789011" but I want to keep the spaces from str1 (that's why I do str1.Left(7) and and not str1.Left(3).
How can I do that (I mean, to get "123       789011")?
0
Comment
Question by:twg
6 Comments
 
LVL 3

Expert Comment

by:ghimireniraj
ID: 2633825
Your code is 100% correct.
There is no way you can get anything else than what you expect to get("123       789011").
Something else must be wrong.

Hope you havenet uset LeftTrim() or things like that.

Your code is absolutely correct.

niraj

0
 
LVL 5

Expert Comment

by:vachooho
ID: 2634354
Probably you did something like GetBuffer() to get buffer to string data and NOT called REleaseBuffer() to free it.

Check your code for this
0
 

Accepted Solution

by:
sisimon earned 30 total points
ID: 2636021
I think  , to  get the result  "123       789011" you simply add this two strings

ie  ,
     CString str3;
     str3 = str1 + str2;

 
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 5

Expert Comment

by:Wyn
ID: 2636129
sisimon ,
CString str3 = str1.Left(7) + str2.Left(6);

is necessary.

Have you counted out the spaces following str1?
It's much more than 4.

The problem is not here.

Regards

 
0
 
LVL 3

Expert Comment

by:V_Bapat
ID: 2638946
twg: There is no problem with your code. I hope you are sure that you have these lines as follows:

CString str1 = "123                     ";
CString str2 = "789011";
CString str3 = str1.Left(7) + str2.Left(6);

and you are not manipulating str1 after initializing!!!

Vicky
0
 
LVL 5

Expert Comment

by:vachooho
ID: 2641049
Probably you did something like GetBuffer() to get buffer to string data and NOT called REleaseBuffer() to free it.

Check your code for this

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

706 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

17 Experts available now in Live!

Get 1:1 Help Now