Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

concatenation of 2 strings

Posted on 2000-03-19
6
Medium Priority
?
202 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 60 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
Loops Section Overview
Suggested Courses

926 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