I don't have idea How can I search word for a sentence in C#. In case the word is anywhere in the sentence.
My plan is if have the word that I set up in anywhere the sentence the button1 will visible.
e.g. => I set up the word is 'ABC' in label1.
if the sentence in textbox1 is : I'am ABC.
or : ABC is here.
or : The ABC is come.
or : 12345ABCDEFG
The Button1 will visible.
I tried coding :
string textToSearchFor = "ABC";
int index = textbox1.Text.IndexOf(textToSearchFor, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
button1.Visible = true;
}
else
{
button1.Visible = false;
}
but It didn’t go as planned.
-Edited-
Because When in textbox1 value is ABC
then button1.Visible is true
But when textbox1 value is ABC is here.
or The ABC is come.
then button1.Visible is false
Please anyone help me how? Thank you.