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:
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:
- I put the addition in a different order like this :* Str1 = " Hello Everyone“ + Str2* - This succeeds for some reason
- I tried this Str1 = "Hello" + " Everyone" - This works
- I tried Str1 = Str2 + "Hello Everyone" - This fails
- 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();
this->ClientSocks->Socks[ConnectionData->SelectedSocket]->MsgsToSend->AddMessage(Msg);
}*
!--removed tag-->
No one has replied yet! Why not be the first?
Sign in or Join us (it's free).