Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / May 2005

Tip: Looking for answers? Try searching our database.

String concatination

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Boni - 04 May 2005 13:37 GMT
Hi all,
String *A="kkkj"
String *B="kkkj"

Is there something easier then
String *C=String::Concat(A,B)
Why can't it just be as in C# C=A+B.
Thanks,
Boni
Tamas Demjen - 04 May 2005 17:27 GMT
> Hi all,
> String *A="kkkj"
[quoted text clipped - 5 lines]
> Thanks,
> Boni

In Beta 2 this works:
   String^ A = "kkkj";
   String^ B = "kkkj";
   String^ C = A + B;
   Console::WriteLine(C);

In VC++ 2003 it is not possible, to the best of my knowledge. You're not
the only one who complained about it, and Microsoft was listening, it
seems to be fixed in VC++ 2005.

If you want to concatenate a lot of strings, use StringBuilder instead.

And if you are asking why C# can do it while MC++ can't, that's because
in MC++ there is a difference between String* and String, while in C#
there's no difference.

Tom
Rodrigo Corral [MVP] - 04 May 2005 17:52 GMT
There is not operator + in the string class.
When you write code like

string a = "A";
string b = "B";
string c = a + b;

the C# compiler is who translates this code in a call to the Concat string's
member function.

Here is the IL code:

.method private hidebysig static void Main(string[] args) cil managed
{
     .entrypoint
     // Code Size: 21 byte(s)
     .maxstack 2
     .locals (
           string text1,
           string text2,
           string text3)
     L_0000: ldstr "A"
     L_0005: stloc.0
     L_0006: ldstr "B"
     L_000b: stloc.1
     L_000c: ldloc.0
     L_000d: ldloc.1
     L_000e: call string string::Concat(string, string)
     L_0013: stloc.2
     L_0014: ret
}

The C++ compiler doesn't do this magic ;).

Signature

Un saludo
Rodrigo Corral González [MVP]

FAQ de microsoft.public.es.vc++
http://rcorral.mvps.org


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.