开发者

c# compare 2 strings

开发者 https://www.devze.com 2023-03-04 03:53 出处:网络
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 an开发者_JAVA技巧ywhere in a TextBox.

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 an开发者_JAVA技巧ywhere in a TextBox.

How do I do this?


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)


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号