java 一个字符串在另一个字符串中出现的个数
public class Test_toString {
public static void main(String[] args)
{
String str1="abcdgihgabcgh"; String str2="abc"; int index=-1; int cnt=0; index=str1.indexOf(str2); while (-1!=index) { ++cnt; index=str1.indexOf( str2,index+str2.length()); } System.out.printf("%d",cnt);}
}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。