Java Utililty Methods String Substring Count

List of utility methods to do String Substring Count

Description

The list of methods to do String Substring Count are organized into topic(s).

Method

intcountSubString(final String aString, final String aSubString)
count Sub String
if (aString == null || aSubString == null || aString.isEmpty() || aString.length() < aSubString.length()) {
    return -1;
String[] wSplited = aString.split(aSubString);
return wSplited.length - 1;
intcountSubstring(final String text, final String substring)
Cuenta las repeticiones de una subcadena dentro de una cadena.
int count = 0;
for (int i = 0; i <= text.length() - substring.length(); i++) {
    if (substring.charAt(0) == text.charAt(i)
            && substring.equals(text.substring(i, i + substring.length()))) {
        count++;
        i += substring.length() - 1;
return count;
intcountSubString(String str, String substr)
count Sub String
int cnt = 0;
int lastindex = str.length();
while (lastindex > -2) {
    lastindex = str.lastIndexOf(substr, lastindex) - 1;
    if (lastindex > -2)
        cnt++;
return cnt;
...
intcountSubstring(String string, String substring)
count Substring
int searchFrom = -1;
int count = 0;
do {
    searchFrom = string.indexOf(substring, searchFrom + 1);
    if (searchFrom != -1) {
        count++;
} while (searchFrom != -1);
...
intcountSubString(String strToFind, String strSearch)
count Sub String
try {
    int intCount = 0;
    for (int intFromIndex = 0; intFromIndex > -1; intCount++) {
        intFromIndex = strToFind.indexOf(strSearch, intFromIndex + ((intCount > 0) ? 1 : 0));
    return intCount - 1;
} catch (Exception Ex) {
    return -1;
...
intcountSubstringOccurrances(String s1, String SubString)
return the number of times the substring occurs in the text - where there are overlaps the count tells how many times the substring could be replaced
int count = 0;
int index = s1.indexOf(SubString);
int sublength = SubString.length();
int start = 0;
while (index > -1) {
    count++;
    start = index + sublength;
    if (start > s1.length() - sublength)
...
intcountSubstrings(String string, String sub)
Counts the number of substring in a string
int count = 0;
int index = -1;
while ((index = string.indexOf(sub, index + 1)) != -1) {
    ++count;
return count;