日期:2014-05-20  浏览次数:20866 次

求子串的个数
例如字符串sabcewewabciowewrabcoewabc,求abc的个数。

------解决方案--------------------
String a = "sabcewewabciowewrabcoewabc ";
StringTokenizer s = new StringTokenizer(a, "abc ");
System.out.println( s.countTokens());
------解决方案--------------------
public int getSubCount(String Content, String Sub)
{
int Count=0;
if(Sub.length()!=0){
Count = Content.length();
Content = Content.replaceAll(Sub, " ");
Count = Count - Content.length();
Count = Count / Sub.length();
}
ruturn Count;
}


public int getSubCount(String Content, String Sub)
{
return Content.split(Sub).length-1 ;
}