黑马程序员——求一个字符串在另一个字符串中的出现次数

来源:互联网 发布:sql学生成绩管理系统 编辑:程序博客网 时间:2024/06/03 20:28

               ----------------------    android培训    java培训   期待与您交流!    ----------------------   
                        

//查找一个字符串在另一个字符串中的出现次数public static void count(String str,String key){int count=0;int index=0;while((index=str.indexOf(key))!=-1){str=str.substring(index+key.length());System.out.println(str);//截取后的字符串count++;}System.out.println("出现的次数:"+count);}//查找一个字符串在另一个字符串中的出现次数public static void count_1(String str,String key){int count=0;int index=0;while((index=str.indexOf(key,index))!=-1){index=index+key.length();count++;}System.out.println("出现的次数:"+count);}
               ----------------------    android培训    java培训   期待与您交流!    ----------------------   
                         详细请查看      http://edu.csdn.net/heima