i'm so confused

Mar 29, 2018 at 7:05am
why doesn't this work? textBox4->Text never wants to equal "test"
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
	private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
		textBox3->Text = "abc";
	}
	private: System::Void timer1_Tick(System::Object^  sender, System::EventArgs^  e) {
		String^ MyString = gcnew String(lib->getString().c_str());
		textBox1->Text = MyString;//MyString = abc
		if (textBox1->Text != textBox4->Text)
		{
			timer2->Enabled = true;
		}
	}
	private: System::Void timer2_Tick(System::Object^  sender, System::EventArgs^  e) {
		textBox1->Text = textBox2->Text;
		if (textBox2->Text == textBox3->Text)
		{
			textBox4->Text = "test";
		}
	}
Last edited on Mar 29, 2018 at 7:06am
Mar 29, 2018 at 7:12am
Are you sure != is comparing object values and not object identities? That is, is it comparing if the operands are two equivalent strings, or if they are the same string object?
Mar 29, 2018 at 7:17am
well it doesn't matter. i know timer2->Enabled comes out true because textBox1->Text sends its value to textBox2->Text
then if (textBox2->Text == textBox3->Text)
{
textBox4->Text = "test";
}
textBox4->Text isn't equaling to "test" for some reason
Mar 29, 2018 at 7:20am
oh wait i just double checked you're right it is the !=
i'm comparing if they are equivalent strings
Last edited on Mar 29, 2018 at 7:25am
Mar 29, 2018 at 7:24am
what operator do i put?
Mar 29, 2018 at 5:59pm
I believe .NET strings have have a .Compare() method that behaves like strcmp().
Mar 29, 2018 at 8:12pm
You can use == or != to compare .NET strings - unlike Java. You need only String::Compare for case-insensitive comparison.
https://msdn.microsoft.com/en-us/library/system.string.op_equality(v=vs.110).aspx
Topic archived. No new replies allowed.