DarkW1nter
DarkW1nter

Reputation: 2851

c# compare 2 strings

I'm looking to do something in C# but just not sure of the syntax.

I return a string from a database and want to check if that string is present anywhere in a TextBox.

How do I do this?

Upvotes: 0

Views: 681

Answers (2)

Uwe Keim
Uwe Keim

Reputation: 40736

Probably this is too obvious?:

if ( myTextBox.Text.Contains(myStringFromDB) )
{
    // Is contained, do something...
}
else
{
    // Is not contained, do something else...
}

For Windows Forms, see this TextBox class, for Web Forms see this TextBox class.

Upvotes: 1

David
David

Reputation: 8650

I think I understand your question.

You can use the Contains method to test if your string is contained within the textbox value

TextBox1.Text.Contains(yourString)

Upvotes: 2

Related Questions