Java String Sub String substringToLast(final String str, final String separator)

Here you can find the source of substringToLast(final String str, final String separator)

Description

substring To Last

License

Apache License

Declaration

public static String substringToLast(final String str, final String separator) 

Method Source Code

//package com.java2s;
/*/*from  ww  w . ja v a2  s . c  om*/
 * Copyright 2004-2010 the Seasar Foundation and the Others.
 *
 * 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 {

    public static String substringToLast(final String str, final String separator) {
        if (isEmpty(str) || isEmpty(separator)) {
            return str;
        }
        int pos = str.lastIndexOf(separator);
        if (pos == -1) {
            return str;
        }
        return str.substring(pos + 1, str.length());
    }

    public static final boolean isEmpty(final String text) {
        return text == null || text.length() == 0;
    }
}

Related

  1. subStringRight(String str, int length)
  2. substrings(String str, int start, int end)
  3. subStrings(String str1, String str2)
  4. substrings(String[] arr, int start, int end)
  5. subStringToInteger(String src, String start, String to)
  6. substringUntil(String org, int begin, char term)
  7. substringUntilMatch(String string, String match)
  8. subStringWhiteSpaces(String str, int maxLen)
  9. subStringWith3Point(String inputStr, int beginIndex, int length)