得到str1在str2中出现的次数 GetCountInStr(string str1,string str2)

  /// <summary>
  /// 得到str1在str2中出现的次数
  /// </summary>
  /// <param name="str1"></param>
  /// <param name="str2"></param>
  /// <returns></returns>
  public static int GetCountInStr(string str1,string str2){
   int count = 0;
   int str1Len = str1.Length;
   for(int i=0;i<=str2.Length-str1Len;i++){
    if(str2.Substring(i,str1Len) == str1)
     count ++;
   }
   return count;
  }
原文地址:https://www.cnblogs.com/King0502/p/2019349.html