int pos = textbox1.Text.IndexOf("YYMM"); if(pos != -1) { textbox1.SelectionStart = pos; textbox1.SelectionLength = 4; // MessageBox("Error"); }