Java String Sub String substringAfterLast(String text, char after)

Here you can find the source of substringAfterLast(String text, char after)

Description

Returns the portion of the overall string that comes after the last occurance of the given string.

License

LGPL

Declaration


public static String substringAfterLast(String text, char after) 

Method Source Code

//package com.java2s;
// Metawidget (licensed under LGPL)

public class Main {
    /**//  w w w .ja va2  s . c  o  m
     * Returns the portion of the overall string that comes after the last occurance of the given
     * string. If the given string is not found in the overall string, returns the entire string.
     */

    public static String substringAfterLast(String text, char after) {

        int indexOf = text.lastIndexOf(after);

        if (indexOf == -1) {
            return text;
        }

        return text.substring(indexOf + 1);
    }

    /**
     * Returns the portion of the overall string that comes after the last occurance of the given
     * string. If the given string is not found in the overall string, returns the entire string.
     */

    public static String substringAfterLast(String text, String after) {

        int indexOf = text.lastIndexOf(after);

        if (indexOf == -1) {
            return text;
        }

        return text.substring(indexOf + after.length());
    }
}

Related

  1. substringAfterLast(String input, String delimiter)
  2. substringAfterLast(String str, String pattern)
  3. substringAfterLast(String str, String separator)
  4. substringAfterLast(String str, String separator)
  5. substringAfterLast(String string, String delimiter)
  6. subStringAfterLastSymbol(String inStr, char symbol)
  7. substringAfterReturnAll(String str, String before)
  8. substringAndchopLastNewline(String text, int start_pos, int end_pos)
  9. subStringArray(String in[], int start, int end)