Java Char Count charCountRight(String str, String sub)

Here you can find the source of charCountRight(String str, String sub)

Description

char Count Right

License

Open Source License

Declaration

public static int charCountRight(String str, String sub) 

Method Source Code

//package com.java2s;

public class Main {

    public static int charCountRight(String str, String sub) {
        if (str == null) {
            return 0;
        }//  ww  w .  j  ava  2  s. co  m

        int charCount = 0;
        String subStr = str;
        int currentLength = subStr.length() - sub.length();
        while (currentLength >= 0 && subStr.substring(currentLength).equals(sub)) {
            charCount++;
            subStr = subStr.substring(0, currentLength);
            currentLength = subStr.length() - sub.length();
        }
        return charCount;
    }
}

Related

  1. charCount(String source, char target)
  2. charCount(String str, char c, boolean countEscaped)
  3. charCount(String str, char chr)
  4. charCount(String str, char sub)
  5. charCount(String subject, String needle)
  6. countChar(char charIn, String stingIn)
  7. countChar(char[] line, char target_char)
  8. countChar(CharSequence chars, char c)
  9. countChar(final int[] locator, final char c)