Android String Sub String Get substringAfterLast(String text, char separator)

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

Description

Gives the substring of the given text after the last occurrence of the given separator.

Parameter

Parameter Description
text a parameter
separator a parameter

Declaration

public static String substringAfterLast(String text, char separator) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from   w w w. j  a  v a2 s .  com
     * Gives the substring of the given text after the last occurrence of the given separator.
     * 
     * If the text does not contain the given separator then "" is returned.
     * 
     * @param text
     * @param separator
     * @return
     */
    public static String substringAfterLast(String text, char separator) {
        if (isEmpty(text)) {
            return text;
        }
        int cPos = text.lastIndexOf(separator);
        if (cPos < 0) {
            return "";
        }
        return text.substring(cPos + 1);
    }

    /**
     * Whether the given string is null or zero-length.
     * 
     * @param text
     * @return
     */
    public static boolean isEmpty(String text) {
        return (text == null) || (text.length() == 0);
    }
}

Related

  1. substringFromLast(final String str, final String separator)
  2. substringToLast(final String str, final String separator)
  3. takeOutFirstChar(String input)
  4. substring(String str, int srcPos, int specialCharsLength)
  5. substringAfter(String text, char c)
  6. substringBefore(String text, char separator)
  7. substringBefore(String text, char separator)
  8. substringBeforeLast(String text, char separator)