Java String Sub String subStrOccurences(String str, String findStr)

Here you can find the source of subStrOccurences(String str, String findStr)

Description

sub Str Occurences

License

Creative Commons License

Parameter

Parameter Description
str a parameter
findStr a parameter

Declaration

public static int subStrOccurences(String str, String findStr) 

Method Source Code

//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;
    }
}

Related

  1. substringToLast(final String str, final String separator)
  2. substringUntil(String org, int begin, char term)
  3. substringUntilMatch(String string, String match)
  4. subStringWhiteSpaces(String str, int maxLen)
  5. subStringWith3Point(String inputStr, int beginIndex, int length)
  6. subStrTime(String strTime)