windows forms, textbox and string comparison
Can somebody please tell me how to get the text from a textbox in a way that is comparable to other strings, ie:
String *myText = textBox1->Text->ToString();
String *myText = textBox1->get_Text();
Both get the value of the textbox but do not compare with other strings, ie:
if the textbox value is Carl and I try to compare them:
if(myText == "Carl"){
MessageBox::Show("You are Carl");
}else{
MessageBox::Show(myText);
}
The second message box is shown with a value of Carl.
Any help would be greatly appreciated.
Regards
Carl
Re: windows forms, textbox and string comparison
What type of object is String?
Does it have a operator definition for the equality operator ==?
Re: windows forms, textbox and string comparison
You are doing the following comparison:
if(myText == "Carl")
What this is doing is testing wether or not these two pointers are pointing to the same object. Even if both strings have the value "Carl" they are still two distinct objects and the comparision will return false.
if(myText.compare("Carl") == 0)
This is comparing the values stored within the actual objects. If they both contain the value "Carl", this method returns zero.