Java String Ends With endsWithIgnoreCase(String p_sStr, String p_sSubStr)

Here you can find the source of endsWithIgnoreCase(String p_sStr, String p_sSubStr)

Description

Same as String#endsWith(String) , but ignoring case

License

Apache License

Parameter

Parameter Description
p_sStr string value
p_sSubStr sub string

Return

true, if substring

Declaration

public static boolean endsWithIgnoreCase(String p_sStr, String p_sSubStr) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from  ww  w .j  av a 2  s. c om*/
     * Same as {@link String#endsWith(String)}, but ignoring case
     * 
     * @param p_sStr string value
     * @param p_sSubStr sub string
     * @return true, if substring
     */
    public static boolean endsWithIgnoreCase(String p_sStr, String p_sSubStr) {
        if (p_sSubStr.length() > p_sStr.length())
            return false;
        int nSubStrLen = p_sSubStr.length();
        int nStrLen = p_sStr.length();
        int nIdx = 1;
        for (int i = nSubStrLen - 1; i >= 0; i--) {
            char cSubStr = p_sSubStr.charAt(i);
            char cStr = p_sStr.charAt(nStrLen - nIdx);
            char cSubStrLC = Character.toLowerCase(cSubStr);
            char cStrLC = Character.toLowerCase(cStr);

            if (cSubStrLC != cStrLC)
                return false;

            nIdx++;
        }

        return true;
    }
}

Related

  1. endsWithIgnoreCase(String baseString, String compareString)
  2. endsWithIgnoreCase(String haystack, String needle)
  3. endsWithIgnoreCase(String input, String suffix)
  4. endsWithIgnoreCase(String input, String... suffixes)
  5. endsWithIgnoreCase(String name, Iterable patterns)
  6. endsWithIgnoreCase(String s, String suffix)
  7. endsWithIgnoreCase(String s, String suffix)
  8. endsWithIgnoreCase(String s, String w)
  9. endsWithIgnoreCase(String seq, String suffix)