//演示例子 string s = "大"; int i = GetStringExistCount("abcdf大大大大dssdf大dfsdfad大sre顶wf大大sda大fwefr", s); Console.WriteLine("搜索到”{0}“在字符串中出现的总次数为[{1}]", s,i); Console.ReadKey();
/// <summary> /// 取出现次数 /// </summary> /// <param name="SumString">总文本</param> /// <param name="SearchString">欲找文本</param> /// <returns>找到返回出现的总次数,没找到返回0</returns> public static int GetStringExistCount(string SumString, string SearchString) { SumString = SumString.Replace(SearchString, "╋"); return SumString.Split(‘╋‘).Length - 1; }
时间: 2024-10-21 12:24:52