我不知道如何在 C# 中搜索一个句子的单词。如果这个词在句子中的任何地方。
我的计划是,如果有我在任何地方设置的词,button1 将可见。
例如 => 我在 label1 中设置了“ABC”这个词。
如果 textbox1 中的句子是 : I'am ABC.
or : ABC is here.
or : The ABC is come.
or :12345ABCDEFG
Button1 将可见。
我试过编码:
string textToSearchFor = "ABC";
int index = textbox1.Text.IndexOf(textToSearchFor, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
button1.Visible = true;
}
else
{
button1.Visible = false;
}
Run Code Online (Sandbox Code Playgroud)
但它没有按计划进行。
-编辑-
因为当 textbox1 中的值是ABCbutton1.Visible 是 true
但是当 textbox1 值为ABC is here.or 时The ABC is come.button1.Visible 为 …