Can't combine strings together properly

SystemString , Strings wont add , String Problem Sydney, Australia
  • 11 years ago

    I've been writing a small program lately in managed C++. In the one part of my program I add attempt to add two System::String(s) together - pretty simple hey. But when I add them together the value of the string stays the same! Example:

    Str1 += Str2 + " Hello Everyone" Output: (Str1 == Str2) only

    This is the most obscure thing ever! I've conducted many tests:

    1. I ran the program on another computer - Result stays the same

         Then I decided to test if the same thing would happen for different combinations of adding the strings:
    2. I put the addition in a different order like this :* Str1 = " Hello Everyone“ + Str2* - This succeeds for some reason
    3. I tried this Str1 = "Hello" + " Everyone" - This works
    4. I tried Str1 = Str2 + "Hello Everyone" - This fails
    5. I tried using a System.Text.StringBuilder class to append the 2 pieces of text seperately - Astonishingly this fails aswell

    I have added up all the facts and figured that possibly the reason behind all this is that it is a memory failure - (very obscure one) but the wierd thing is that I've even tried it on another computer so what's happening.

    Here is my full subroutine: - PS just ignore all the "Socks" functions and stuff below because I built some of these classes

    *System::Void buttonTalkClick(System::Object^ sender, System::EventArgs^ e) { System::Text::StringBuilder^ Builder = gcnew System::Text::StringBuilder(); if((ClientTable->SelectedIndices->Count > 0) && (ConnectionData->ClientAvailable)) { int SelectedIndex = this->ClientTable->SelectedIndices[0]; Builder->Append(this->ClientTable->Items[SelectedIndex]->Text); Builder->Append(" "); } Builder->Append(this->textbox_TalkBox->Text); MsgCore::rNewTextMsg::Text += Builder->ToString();

      array<unsigned char> ^ Msg = MsgCore::rNewTextMsg::GetBuffer();


Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why.”