Here you can find the source of lastIndexOfImpl(final String str, final String search, final int fromIndex, final boolean ignoreCase)
Parameter | Description |
---|---|
str | the source string, which can't be null nor empty. |
search | the substring to be seearched, which can't be null nor empty. |
fromIndex | the index of the source string where to start searching backward. |
ignoreCase | whether to ignore case while comparing strings. |
private static int lastIndexOfImpl(final String str, final String search, final int fromIndex, final boolean ignoreCase)
//package com.java2s; /*/*from www.java2 s. c o m*/ * Copyright (c) 2014 Haixing Hu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ public class Main { /** * Searchs the index of the last occurrence of a substring in a string. * * @param str * the source string, which can't be null nor empty. * @param search * the substring to be seearched, which can't be null nor empty. * @param fromIndex * the index of the source string where to start searching backward. * @param ignoreCase * whether to ignore case while comparing strings. * @return the index of the last occurrence of a substring in the source * string. */ private static int lastIndexOfImpl(final String str, final String search, final int fromIndex, final boolean ignoreCase) { // assume str != null && search != null && str.length() > 0 && // search.length() > 0 && fromIndex >= 0 && fromIndex < str.length() final int searchLen = search.length(); for (int i = fromIndex; i >= 0; --i) { if (str.regionMatches(ignoreCase, i, search, 0, searchLen)) { return i; } } return -1; } }