while (M_int_index != -1) { M_int_start = 0; M_int_end = richTextBox1.Text.Trim().Length; M_int_index = richTextBox1.Find(this.textBox1.Text.Trim(), M_int_start, M_int_end, RichTextBoxFinds.None); if (M_int_index == -1) { MessageBox.Show("字符串" + this.textBox1.Text + "一共出现了" + P_int_num.ToString() + "次。", "信息", MessageBoxButtons.OK, MessageBoxIcon.Information); M_int_index = 0; while (M_int_index != -1) { M_int_start = 0; M_int_end = richTextBox1.Text.Trim().Length; M_int_index = richTextBox1.Find("计数", M_int_start, M_int_end, RichTextBoxFinds.None); if (M_int_index != -1) { richTextBox1.SelectedText = this.textBox1.Text.Trim(); M_int_index += this.textBox1.Text.Length; } } } else { richTextBox1.SelectedText = "计数"; M_int_index += this.textBox1.Text.Length; P_int_num += 1; } } |
vb.net的代码如下
Dim regex As Regex
Dim count as Integer
regex = New Regex("abc")
count=regex.Matches("abcabcabcabc", "abc").Count()
using System.Text.RegularExpressions;
string s = @"a\w";
string s2 = @"defa\wdfdfsdfa\wddfdsaw";
Regex re = new Regex(Regex.Escape(s), RegexOptions.IgnoreCase|RegexOptions.Singleline);
MatchCollection mc = re.Matches(s2);
Console.WriteLine(mc.Count);
0 评论:
发表评论