Java String Starts Wtih startsWithIgnoreCaseAndWs(String searchIn, String searchFor)

Here you can find the source of startsWithIgnoreCaseAndWs(String searchIn, String searchFor)

Description

Determines whether or not the string 'searchIn' contains the string 'searchFor', disregarding case and leading whitespace

License

Open Source License

Parameter

Parameter Description
searchIn the string to search in
searchFor the string to search for

Return

true if the string starts with 'searchFor' ignoring whitespace

Declaration

public static boolean startsWithIgnoreCaseAndWs(String searchIn, String searchFor) 

Method Source Code

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

public class Main {
    /**//from   w w  w .ja  va2  s.  c  o  m
     * Determines whether or not the string 'searchIn' contains the string
     * 'searchFor', disregarding case and leading whitespace
     *
     * @param searchIn  the string to search in
     * @param searchFor the string to search for
     * @return true if the string starts with 'searchFor' ignoring whitespace
     */
    public static boolean startsWithIgnoreCaseAndWs(String searchIn, String searchFor) {
        return startsWithIgnoreCaseAndWs(searchIn, searchFor, 0);
    }

    /**
     * Determines whether or not the string 'searchIn' contains the string
     * 'searchFor', disregarding case and leading whitespace
     *
     * @param searchIn  the string to search in
     * @param searchFor the string to search for
     * @param beginPos  where to start searching
     * @return true if the string starts with 'searchFor' ignoring whitespace
     */

    public static boolean startsWithIgnoreCaseAndWs(String searchIn, String searchFor, int beginPos) {
        if (null == searchIn) {
            return true;
        }

        int inLength = searchIn.length();

        for (; beginPos < inLength; beginPos++) {
            if (!Character.isWhitespace(searchIn.charAt(beginPos))) {
                break;
            }
        }

        return startsWithIgnoreCase(searchIn, beginPos, searchFor);
    }

    /**
     * Determines whether or not the string 'searchIn' contains the string
     * 'searchFor', dis-regarding case starting at 'startAt' Shorthand for a
     * String.regionMatch(...)
     *
     * @param searchIn  the string to search in
     * @param startAt   the position to start at
     * @param searchFor the string to search for
     * @return whether searchIn starts with searchFor, ignoring case
     */
    public static boolean startsWithIgnoreCase(String searchIn, int startAt, String searchFor) {
        return searchIn.regionMatches(true, startAt, searchFor, 0, searchFor.length());
    }
}

Related

  1. startsWithIgnoreCase(String text, String value)
  2. startsWithIgnoreCase(String thisString, String prefix)
  3. startsWithIgnoreCase(String whole, String prefix)
  4. startsWithIgnoreCase(String[] compoundName, String[] prefix)
  5. startsWithIgnoreCaseAndNonAlphaNumeric(String searchIn, String searchFor)
  6. startsWithIgnoreCaseAndWs(String searchIn, String searchFor, int beginPos)
  7. startsWithIgnoreWhitespace(String str, String prefix)
  8. startsWithIgnoreWhitespaces(String prefix, String string)
  9. startsWithIndex(String[] prefixes, String fullPath)