C#取字符串包含另一字符串的个数

int   GetAppearTimes(string   str1,string   str2){   
  int   i=0;   
  while(str1.IndexOf(str2)>=0){   
  str1=str1.Substring(str1.IndexOf(str2)+str2.Length);   
  i++;   
  }   
  return   i;   
  }   


 int   GetAppearTimes(string   str1,string   str2){   
  Regex   ex=new   Regex(str2);   
  return   ex.Matches(str1).Count;   
  }   


Regex.Matches(str1,str2).Count;


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/yxtyxt3311/archive/2007/03/05/1521308.aspx
原文地址:https://www.cnblogs.com/xiaofengfeng/p/1901470.html