Solved

concatenation of 2 strings

Posted on 2000-03-19
6
196 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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Error on moodle after upgrade 3 140
dog bark java program 15 105
tripleUp challenge 7 86
Sed question 2 100
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 …
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.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

791 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