Java:判断字符串中包含某字符的个数
JAVA中查询一个词在内容中出现的次数:
public int getCount(String str,String key){ if(str == null || key == null || "".equals(str.trim()) || "".equals(key.trim())){ return 0; } int count = 0; int index = 0; while((index=str.indexOf(key,index))!=-1){ index = index+key.length(); count++; } return count; }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/16762.html