Solved

concatenation of 2 strings

Posted on 2000-03-19
6
199 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
[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 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
Industry Leaders: 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!

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses

632 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