Java String Starts Wtih startsWithIgnoreCase(String str, String prefix)

Here you can find the source of startsWithIgnoreCase(String str, String prefix)

Description

Checks if the given String begins with the given prefix, ignoring case.

License

Open Source License

Parameter

Parameter Description
str The String to check.
prefix The prefix to check the String for.

Return

True if the given String begins with the given prefix, otherwise false.

Declaration

public static boolean startsWithIgnoreCase(String str, String prefix) 

Method Source Code

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

public class Main {
    /**/*from  w  ww .  j a  va  2 s.  co  m*/
     * Checks if the given String begins with the given prefix, ignoring case.
     * 
     * @param str The String to check.
     * @param prefix The prefix to check the String for.
     * 
     * @return True if the given String begins with the given prefix, otherwise false.
     */
    public static boolean startsWithIgnoreCase(String str, String prefix) {
        if (str == null)
            throw new IllegalArgumentException("Parameter 'str' cannot be null!");
        if (prefix == null)
            throw new IllegalArgumentException("Parameter 'prefix' cannot be null!");

        if (str.length() < prefix.length())
            return false;

        int offset = (prefix.length() + 1 <= str.length()) ? prefix.length() : str.length();

        String beginning = str.substring(0, offset);

        return beginning.equalsIgnoreCase(prefix);
    }
}

Related

  1. startsWithIgnoreCase(String searchIn, String searchFor)
  2. startsWithIgnoreCase(String seq, String prefix)
  3. startsWithIgnoreCase(String startString, String anotherString)
  4. startsWithIgnoreCase(String str, String prefix)
  5. startsWithIgnoreCase(String str, String prefix)
  6. startsWithIgnoreCase(String str, String prefix)
  7. startsWithIgnoreCase(String str, String prefix)
  8. startsWithIgnoreCase(String str, String prefix)
  9. startsWithIgnoreCase(String str, String start)