0

I have a variable test..

String test = TextBox1.Text;

I want to know if the user enters into this variable 04151.

2
  • 3
    I think you might need to lookup some beginner C# tutorials... Commented Mar 8, 2011 at 13:19
  • There's nothing wrong with beginner questions. Especially since it is a library question, essentially. Commented Mar 8, 2011 at 13:21

4 Answers 4

4
if (test == "04151")
{
    MessageBox.Show("Yep!");
}


Edit:

if (test.Contains("04151"))
{
    MessageBox.Show("Yep!");
}
Sign up to request clarification or add additional context in comments.

2 Comments

if the user enters "Ex H 4 04151" how do I check?
@sowulo - test.Contains("04151")
1
if( test == "04151" )
{
   //04151 was entered
}

?

If this is some type of checking a password, I would strongly urge you to do it in a safer way than checking towards a hard coded string inside your app. There are many issues with that approach. For one, you will have to recompile your program to alter your password.

2 Comments

Based on his comment above, I don't think that it is a password.
@John - Nope, but I was afraid it could be when I read his initial question ;)
0

You could put the other answers in the TextChanged event, to check it every time the user changes the text

Comments

0
    public bool Matches(string test)
    {
        return String.Compare(test, "04151", true) == 0;
    }

1 Comment

you couldn't manage to make a single string comparison more difficult for a beginner? :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.