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

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

Description

starts With Ignore Case

License

Apache License

Declaration

public static boolean startsWithIgnoreCase(final String str, final String prefix) 

Method Source Code

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

public class Main {

    public static boolean startsWithIgnoreCase(final String str, final String prefix) {
        return startsWith(str, prefix, true);
    }//from  w ww.j a v  a 2s . com

    public static boolean startsWithIgnoreCase(final String str, final String prefix, final int offset) {

        if (str == null || prefix == null) {
            return (str == null && prefix == null);
        }

        if (str.length() < offset) {
            return false;
        }

        final String subStr = str.substring(offset);
        return startsWithIgnoreCase(subStr, prefix);

    }

    private static boolean startsWith(final String str, final String prefix, boolean ignoreCase) {
        if (str == null || prefix == null) {
            return (str == null && prefix == null);
        }
        if (prefix.length() > str.length()) {
            return false;
        }
        return str.regionMatches(ignoreCase, 0, prefix, 0, prefix.length());
    }
}

Related

  1. startsWithIgnoreCase(final String base, final String start)
  2. startsWithIgnoreCase(final String haystack, final String needle)
  3. startsWithIgnoreCase(final String iFirst, final String iSecond)
  4. startsWithIgnoreCase(final String input, final String prefix)
  5. startsWithIgnoreCase(final String source, final String target)
  6. startsWithIgnoreCase(final String str, final String prefix)
  7. startsWithIgnoreCase(final String string, final String start)
  8. startsWithIgnoreCase(final String stringToCheck, final String prefix)
  9. startsWithIgnoreCase(final String target1, final String target2)