Java String Sub String substringAfter(String str, String separator)

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

Description

substring After

License

Apache License

Declaration

public static String substringAfter(String str, String separator) 

Method Source Code

//package com.java2s;
/*/*from  ww  w . j  a  va2  s. c  om*/
 * Copyright 2002-2012 the original author or authors.
 *
 * 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 substringAfter(String str, String separator) {
        if (isEmpty(str)) {
            return str;
        } else if (separator == null) {
            return "";
        } else {
            int pos = str.indexOf(separator);
            return pos == -1 ? "" : str.substring(pos + separator.length());
        }
    }

    /**
     * Check whether the given String is empty.
     * <p>This method accepts any Object as an argument, comparing it to
     * {@code null} and the empty String. As a consequence, this method
     * will never return {@code true} for a non-null non-String object.
     * <p>The Object signature is useful for general attribute handling code
     * that commonly deals with Strings but generally has to iterate over
     * Objects since attributes may e.g. be primitive value objects as well.
     *
     * @param str the candidate String
     * @since 3.2.1
     */
    public static boolean isEmpty(Object str) {
        return (str == null || "".equals(str));
    }

    public static boolean equals(String str1, String str2) {
        return str1 == null ? str2 == null : str1.equals(str2);
    }
}

Related

  1. substringAfter(String sourceStr, String expr)
  2. substringAfter(String str, int beginChar, boolean last)
  3. substringAfter(String str, String delimiter)
  4. substringAfter(String str, String separator)
  5. substringAfter(String str, String separator)
  6. substringAfter(String string, String delim)
  7. substringAfter(String string, String delimiter)
  8. substringAfter(String template, String toFind, String defaultTo)
  9. substringAfter(String text, int index)