Returns the substring after the first occurrence of a delimiter. - Java java.lang

Java examples for java.lang:String Substring

Description

Returns the substring after the first occurrence of a delimiter.

Demo Code


//package com.java2s;

public class Main {
    /**//w ww.  j av a 2s  .co m
     * Returns the substring after the first occurrence of a delimiter. The
     * delimiter is not part of the result.
     * @param string    String to get a substring from.
     * @param delimiter String to search for.
     * @return          Substring after the last occurrence of the delimiter.
     */
    public static String substringAfter(String string, String delimiter) {
        int pos = string.indexOf(delimiter);

        return pos >= 0 ? string.substring(pos + delimiter.length()) : "";
    }
}

Related Tutorials