Java String Ends With endsWithIgnoreCase(String haystack, String needle)

Here you can find the source of endsWithIgnoreCase(String haystack, String needle)

Description

Checks to see if a string ends with another string in a case-insensitive manner.

License

Open Source License

Parameter

Parameter Description
haystack the main string
needle the string to test against the main string

Return

true if it matches, false otherwise

Declaration

public static boolean endsWithIgnoreCase(String haystack, String needle) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w w  w  . j a v  a2  s.c o  m
     * Checks to see if a string ends with another string in a case-insensitive manner.
     *
     * @param haystack the main string
     * @param needle the string to test against the main string
     * @return true if it matches, false otherwise
     */
    public static boolean endsWithIgnoreCase(String haystack, String needle) {
        if (needle.length() > haystack.length()) {
            return false;
        }

        for (int i = 0; i < needle.length(); i++) {
            int start = haystack.length() - needle.length() + i;
            if (!haystack.substring(start, start + 1).equalsIgnoreCase(needle.substring(i, i + 1))) {
                return false;
            }
        }

        return true;
    }
}

Related

  1. endsWithIgnoreCase(final String text, final String suffix)
  2. endsWithIgnoreCase(final String text, final String suffix)
  3. endsWithIgnoreCase(Object string, Object suffix)
  4. endsWithIgnoreCase(String a, String b)
  5. endsWithIgnoreCase(String baseString, String compareString)
  6. endsWithIgnoreCase(String input, String suffix)
  7. endsWithIgnoreCase(String input, String... suffixes)
  8. endsWithIgnoreCase(String name, Iterable patterns)
  9. endsWithIgnoreCase(String p_sStr, String p_sSubStr)