static void Main(string[] args)
{
//方式1: 输出结果count 为 2
string testString = "asdf【zbdb】dsafasdfer23hihweiioqhorhwqpersn【zbdb】";
Regex rege = new Regex("zbdb", RegexOptions.Compiled);
int count = rege.Matches(testString).Count;
Console.WriteLine("方式1: 输出结果: count为" + count);
//方式2 :输出结果为三
string str = "【张三】李四王五赵六今天一起看电影,可是【张三】今天吃了辣条和冰棍导致
肚子疼,然后【张三】就坐高铁回家拉稀去了";
int repeatCount = 0; //重复次数
string search = "张三"; //要查的字符串
for (int i = 0; i < str.Length - search.Length; i++)
{
if (str.Substring(i, search.Length) == search)
{
repeatCount++;
}
}
Console.WriteLine("方式2: 输出结果: repeatCount为" + repeatCount);
Console.ReadLine();
}