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

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

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
beginPos where to start searching

Return

true if the string starts with 'searchFor' ignoring whitespace

Declaration


public static boolean startsWithIgnoreCaseAndWs(String searchIn,
        String searchFor, int beginPos) 

Method Source Code

//package com.java2s;
/*/*from w w w. j av  a  2 s.c  o  m*/
 Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.

 The MySQL Connector/J is licensed under the terms of the GPLv2
 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>, like most MySQL Connectors.
 There are special exceptions to the terms and conditions of the GPLv2 as it is applied to
 this software, see the FLOSS License Exception
 <http://www.mysql.com/about/legal/licensing/foss-exception.html>.

 This program is free software; you can redistribute it and/or modify it under the terms
 of the GNU General Public License as published by the Free Software Foundation; version 2
 of the License.

 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 See the GNU General Public License for more details.

 You should have received a copy of the GNU General Public License along with this
 program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth
 Floor, Boston, MA 02110-1301  USA

 */

public class Main {
    /**
     * 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 (searchIn == null) {
            return searchFor == null;
        }

        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' starts with one of the strings in 'searchFor', disregarding case
     * and leading whitespace
     * 
     * @param searchIn
     *            the string to search in
     * @param searchFor
     *            the string array to search for
     * 
     * @return the 'searchFor' array index that matched or -1 if none matches
     */
    public static int startsWithIgnoreCaseAndWs(String searchIn,
            String[] searchFor) {
        for (int i = 0; i < searchFor.length; i++) {
            if (startsWithIgnoreCaseAndWs(searchIn, searchFor[i], 0)) {
                return i;
            }
        }
        return -1;
    }

    /**
     * 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());
    }

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

Related

  1. startsWithIgnoreCase(String thisString, String prefix)
  2. startsWithIgnoreCase(String whole, String prefix)
  3. startsWithIgnoreCase(String[] compoundName, String[] prefix)
  4. startsWithIgnoreCaseAndNonAlphaNumeric(String searchIn, String searchFor)
  5. startsWithIgnoreCaseAndWs(String searchIn, String searchFor)
  6. startsWithIgnoreWhitespace(String str, String prefix)
  7. startsWithIgnoreWhitespaces(String prefix, String string)
  8. startsWithIndex(String[] prefixes, String fullPath)
  9. startsWithLenient(final String s, final String[] matches, final int[] minChars, final boolean acceptTrailing)