Here you can find the source of indexOfIgnoreCase(String str, String substring)
Parameter | Description |
---|---|
str | the string in which to search for the <tt>substring</tt> argument |
substring | the substring to search for in <tt>str</tt> |
public static int indexOfIgnoreCase(String str, String substring)
//package com.java2s; /*/*from w ww. j av a2s . co m*/ * 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, either version 3 of the License, or * (at your option) any later version. * * 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, see <http://www.gnu.org/licenses/>. */ import java.util.*; public class Main { /** * Helper method to obtain the starting index of a substring within another * string, ignoring their case. This method is expensive because it has * to set each character of each string to lower case before doing the * comparison. Uses the default <code>Locale</code> for case conversion. * * @param str the string in which to search for the <tt>substring</tt> * argument * @param substring the substring to search for in <tt>str</tt> * @return if the <tt>substring</tt> argument occurs as a substring within * <tt>str</tt>, then the index of the first character of the first such * substring is returned; if it does not occur as a substring, -1 is * returned */ public static int indexOfIgnoreCase(String str, String substring) { return indexOfIgnoreCase(str, substring, Locale.getDefault()); } /** * Helper method to obtain the starting index of a substring within another * string, ignoring their case. This method is expensive because it has * to set each character of each string to lower case before doing the * comparison. * * @param str the string in which to search for the <tt>substring</tt> * argument * @param substring the substring to search for in <tt>str</tt> * @param locale the <code>Locale</code> to use when converting the * case of <code>str</code> and <code>substring</code>. This is necessary because * case conversion is <code>Locale</code> specific. * @return if the <tt>substring</tt> argument occurs as a substring within * <tt>str</tt>, then the index of the first character of the first such * substring is returned; if it does not occur as a substring, -1 is * returned */ public static int indexOfIgnoreCase(String str, String substring, Locale locale) { // Look for the index after the expensive conversion to lower case. return str.toLowerCase(locale).indexOf(substring.toLowerCase(locale)); } }