Java String Last Index Of lastIndexOfAnyBut(String srcString, String validString)

Here you can find the source of lastIndexOfAnyBut(String srcString, String validString)

Description

last Index Of Any But

License

Open Source License

Declaration

public static int lastIndexOfAnyBut(String srcString, String validString) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright ? 2000, 2007 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which is available at/*from   w  w  w .ja v  a 2s.  c  om*/
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

public class Main {
    public static int lastIndexOfAnyBut(String srcString, String validString) {
        int result = -1;
        int srcLen = srcString.length();

        // walk backward to find if a char within srcString is in validString
        for (int i = srcLen - 1; i >= 0; i--) {
            // not found, stop it
            if (validString.indexOf(srcString.charAt(i)) == -1) {
                result = i;
                break;
            }

        }

        return result;
    }
}

Related

  1. lastIndexOf(String text, String key, int num)
  2. lastIndexOf(String what, String within)
  3. lastIndexOf(StringBuffer buf, String str)
  4. lastIndexOfAny(final String delimiters, final String str)
  5. lastIndexOfAny(String str, String search, int offset)
  6. lastIndexOfAnyDelimiter(String str, int fromIndex, String delimiters)
  7. lastIndexOfIgnoreCase(String pString, String pLookFor)
  8. lastIndexOfIgnoreCase(String s, String substr)
  9. lastIndexOfIgnoreCase(String source, String str, int fromIndex)