鲨丁鱼.net技术小栈

这里讨论.net的web和form开发,还有其它关于WEB开发和安全的全部知识点,顺带一些经典的有意思的杂文!
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  /// <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;
  }