String concatination

  • Thread starter Thread starter Boni
  • Start date Start date
B

Boni

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
 
Boni said:
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

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
 
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 ;).


--
Un saludo
Rodrigo Corral González [MVP]

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