Here you can find the source of substringBeforeLastChar(String str, String separator)
public static String substringBeforeLastChar(String str, String separator)
//package com.java2s; //License from project: Apache License public class Main { private static final int INDEX_NOT_FOUND = -1; public static String substringBeforeLastChar(String str, String separator) { if (isEmpty(str) || isEmpty(separator)) { return str; }/*from w w w. jav a2 s .co m*/ int pos = str.lastIndexOf(separator); if (pos == INDEX_NOT_FOUND) { return str; } if (pos == 0) { return ""; } return str.substring(pos - 1, pos); } /** * <p> * Checks if a CharSequence is empty ("") or null. * </p> * <p> * <pre> * StringUtils.isEmpty(null) = true * StringUtils.isEmpty("") = true * StringUtils.isEmpty(" ") = false * StringUtils.isEmpty("bob") = false * StringUtils.isEmpty(" bob ") = false * </pre> * <p> * <p> * NOTE: This method changed in Lang version 2.0. It no longer trims the * CharSequence. That functionality is available in isBlank(). * </p> * * @param cs the CharSequence to check, may be null * @return {@code true} if the CharSequence is empty or null * @since 3.0 Changed signature from isEmpty(String) to * isEmpty(CharSequence) */ public static boolean isEmpty(CharSequence cs) { return cs == null || cs.length() == 0; } }