Solved

concatenation of 2 strings

Posted on 2000-03-19
6
197 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
Independent Software Vendors: 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

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

Suggested Solutions

Title # Comments Views Activity
zeroMAx challenge 20 126
sumHeights2  challenge 7 130
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 1,287
Problem to App 4 118
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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