CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2005
    Posts
    4

    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

  2. #2
    Join Date
    Feb 2002
    Location
    Krispl, Austria
    Posts
    197

    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.

  3. #3
    Join Date
    Jul 2005
    Location
    Ontario, Canada
    Posts
    107

    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
  •  





Click Here to Expand Forum to Full Width

Featured