Android String Search lastIndexNotOf(String str, String chars, int fromIndex)

Here you can find the source of lastIndexNotOf(String str, String chars, int fromIndex)

Description

Finds the last index in str of a character not in the characters in 'chars' (similar to ANSI string.find_last_not_of).

License

Apache License

Declaration

// TODO(kevinb): after adding fromIndex versions of (last)IndexOf to
// CharMatcher, deprecate this
public static int lastIndexNotOf(String str, String chars, int fromIndex) 

Method Source Code

//package com.java2s;
/**//from  w  w w  .  j  av a2  s  .c  o m
 * Copyright (c) 2000, Google Inc.
 *
 * 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 {
    /**
     * Finds the last index in str of a character not in the characters
     * in 'chars' (similar to ANSI string.find_last_not_of).
     *
     * Returns -1 if no such character can be found.
     *
     * <p><b>Note:</b> If {@code fromIndex} is zero, use {@link CharMatcher}
     * instead for this: {@code CharMatcher.noneOf(chars).lastIndexIn(str)}.
     */
    // TODO(kevinb): after adding fromIndex versions of (last)IndexOf to
    // CharMatcher, deprecate this
    public static int lastIndexNotOf(String str, String chars, int fromIndex) {
        fromIndex = Math.min(fromIndex, str.length() - 1);

        for (int pos = fromIndex; pos >= 0; pos--) {
            if (chars.indexOf(str.charAt(pos)) < 0) {
                return pos;
            }
        }

        return -1;
    }
}

Related

  1. findFirstNotOf(String str, String chars)
  2. findFirstOf(String str, String chars)
  3. findLastNotOf(String str, String chars)
  4. findLastOf(String str, String chars)
  5. firstCharUpper(String myString)