Java String Substring Count countSubString(String str, String substr)

Here you can find the source of countSubString(String str, String substr)

Description

count Sub String

License

Open Source License

Declaration

public static int countSubString(String str, String substr) 

Method Source Code

//package com.java2s;

public class Main {
    /** @METHOD */
    public static int countSubString(String str, String substr) {
        int cnt = 0;
        int lastindex = str.length();
        while (lastindex > -2) {
            lastindex = str.lastIndexOf(substr, lastindex) - 1;
            if (lastindex > -2)
                cnt++;/*from   w w w .  j a v  a 2 s.c om*/
        }
        return cnt;
    }
}

Related

  1. countSubString(final String aString, final String aSubString)
  2. countSubstring(final String text, final String substring)
  3. countSubstring(String string, String substring)
  4. countSubString(String strToFind, String strSearch)
  5. countSubstringOccurrances(String s1, String SubString)
  6. countSubstrings(String string, String sub)