Java String Sub String substringBeforeLast(final String str, final String separator)

Here you can find the source of substringBeforeLast(final String str, final String separator)

Description

substring Before Last

License

Open Source License

Declaration

public static String substringBeforeLast(final String str, final String separator) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static final int INDEX_NOT_FOUND = -1;

    public static String substringBeforeLast(final String str, final String separator) {
        if (isEmpty(str) || isEmpty(separator)) {
            return str;
        }//from  w  w  w.j av  a2  s.c o m
        final int pos = str.lastIndexOf(separator);
        if (pos == INDEX_NOT_FOUND) {
            return str;
        }
        return str.substring(0, pos);
    }

    public static boolean isEmpty(final CharSequence cs) {
        return cs == null || cs.length() == 0;
    }
}

Related

  1. substringBefore(String string, String delimiter)
  2. substringBefore(String text, String str)
  3. substringBeforeChar(String str, int separator)
  4. substringBeforeFirst(String string, String delimiter)
  5. subStringBeforeFirstTab(final String s)
  6. substringBeforeLast(String str, String separator)
  7. substringBeforeLast(String str, String separator)
  8. subStringBeforeLast(String str, String separator)
  9. substringBeforeLast(String text, String separator)