c# Search specified string inside textbox code example
Example 1: c# Search specified string inside textbox
int index = 0;
string temp = richTextBox1.Text;
richTextBox1.Text = "";
richTextBox1.Text = temp;
while (index < richTextBox1.Text.LastIndexOf(textBox1.Text))
{
richTextBox1.Find(textBox1.Text, index, richTextBox1.TextLength, RichTextBoxFinds.None);
richTextBox1.SelectionBackColor = Color.Yellow;
index = richTextBox1.Text.IndexOf(textBox1.Text, index) + 1;
}
Example 2: c# Search specified string inside textbox
int pos = textbox1.Text.IndexOf("YYMM");
if(pos != -1)
{
textbox1.SelectionStart = pos;
textbox1.SelectionLength = 4;
}