111,101
社区成员




string find = "string";
for (int i = 0; i < this.richTextBox1.Text.Length;i++ )
{
int index = this.richTextBox1.Find(find,i,RichTextBoxFinds.MatchCase);
this.richTextBox1.SelectionBackColor = Color.Red;
}
string find = "string";string key = Regex.Escape(textBox1.Text);
Regex reg = new Regex(key);
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox1.SelectionStart = m.Index;
richTextBox1.SelectionLength = m.Value.Length;
richTextBox1.SelectionBackColor = Color.LightBlue;
}
//如果要忽略大小写,正则替换为
Regex reg = new Regex(@"(?i)" + key);
string key = Regex.Escape(textBox1.Text);
Regex reg = new Regex(@"(?m)^" + key);
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox1.SelectionStart = m.Index;
richTextBox1.SelectionLength = m.Value.Length;
richTextBox1.SelectionFont = new Font(richTextBox1.SelectionFont, FontStyle.Bold);
}
[/Quote]