Here you can find the source of subStrOccurences(String str, String findStr)
Parameter | Description |
---|---|
str | a parameter |
findStr | a parameter |
public static int subStrOccurences(String str, String findStr)
//package com.java2s; //License from project: Creative Commons License public class Main { /**/* w ww . j a v a 2 s . c om*/ * * @param str * @param findStr * @return */ public static int subStrOccurences(String str, String findStr) { int lastIndex = 0, count = 0; while (lastIndex != -1) { lastIndex = str.indexOf(findStr, lastIndex); if (lastIndex != -1) { count++; lastIndex += findStr.length(); } } return count; } }