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

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

Description

Tests if this string starts with the specified prefix, ignoring case

License

Open Source License

Parameter

Parameter Description
input the input
prefix the prefix

Return

True if the input starts with the prefix when ignoring case, False if not

Declaration

public static boolean startsWithIgnoreCase(String input, String prefix) 

Method Source Code

//package com.java2s;
/*//www .ja va 2 s.c o  m
 * This file is part of SpoutAPI.
 *
 * Copyright (c) 2011-2012, Spout LLC <http://www.spout.org/>
 * SpoutAPI is licensed under the Spout License Version 1.
 *
 * SpoutAPI is free software: you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation, either version 3 of the License, or (at your option)
 * any later version.
 *
 * In addition, 180 days after any changes are published, you can use the
 * software, incorporating those changes, under the terms of the MIT license,
 * as described in the Spout License Version 1.
 *
 * SpoutAPI 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 Lesser General Public License for
 * more details.
 *
 * You should have received a copy of the GNU Lesser General Public License,
 * the MIT license and the Spout License Version 1 along with this program.
 * If not, see <http://www.gnu.org/licenses/> for the GNU Lesser General Public
 * License and see <http://spout.in/licensev1> for the full license, including
 * the MIT license.
 */

public class Main {
    /**
     * Tests if this string starts with the specified prefix, ignoring case
     * 
     * @param input the input
     * @param prefix the prefix
     * @return True if the input starts with the prefix when ignoring case, False if not
     */
    public static boolean startsWithIgnoreCase(String input, String prefix) {
        if (input == null || prefix == null || prefix.length() > input.length()) {
            return false;
        } else {
            for (int i = 0; i < prefix.length(); i++) {
                if (!equalsIgnoreCase(prefix.charAt(i), input.charAt(i))) {
                    return false;
                }
            }
            return true;
        }
    }

    /**
     * Gets whether two characters equal each other, while ignoring case.
     * 
     * @param input1 to use
     * @param input2 to use
     * @return True if input1 and input2 equal when ignoring case, False if not
     */
    public static boolean equalsIgnoreCase(char input1, char input2) {
        return Character.toLowerCase(input1) == Character.toLowerCase(input2);
    }
}

Related

  1. startsWithIgnoreCase(final String value, final String possiblePrefix)
  2. startsWithIgnoreCase(String a, String b)
  3. startsWithIgnoreCase(String baseString, String compareString)
  4. startsWithIgnoreCase(String haystack, String needle)
  5. startsWithIgnoreCase(String haystack, String pattern)
  6. startsWithIgnoreCase(String inputValue, String prefix)
  7. startsWithIgnoreCase(String main, String with)
  8. startsWithIgnoreCase(String name, Iterable patterns)
  9. startsWithIgnoreCase(String originalString, String checkPhrase)