|
-
July 21st, 2005, 04:04 AM
#1
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
-
July 21st, 2005, 04:10 AM
#2
Re: windows forms, textbox and string comparison
What type of object is String?
Does it have a operator definition for the equality operator ==?
Requests such as
"I need to write an new language compiler by next week, I have teach yourself c++ in 21 days, can someone give me example code?" will be ignored.
-
July 21st, 2005, 08:50 AM
#3
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|