Here you can find the source of substringBeforeLast(String text, char separator)
Parameter | Description |
---|---|
text | a parameter |
separator | a parameter |
public static String substringBeforeLast(String text, char separator)
//package com.java2s; public class Main { /**/*from w w w . j a v a2s . c o m*/ * Gives the substring of the given text before the last occurrence of the given separator. * * If the text does not contain the given separator then the given text is returned. * * @param text * @param separator * @return */ public static String substringBeforeLast(String text, char separator) { if (isEmpty(text)) { return text; } int cPos = text.lastIndexOf(separator); if (cPos < 0) { return text; } return text.substring(0, cPos); } /** * Whether the given string is null or zero-length. * * @param text * @return */ public static boolean isEmpty(String text) { return (text == null) || (text.length() == 0); } }