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

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

Description

substring Before Last

License

Apache License

Declaration

public static String substringBeforeLast(String str, String separator) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static String substringBeforeLast(String str, String separator) {
        if (str == null || separator == null || str.length() == 0 || separator.length() == 0) {
            return str;
        }/*ww  w  .j  a v  a2 s  .  c om*/
        int pos = str.lastIndexOf(separator);
        if (pos == -1) {
            return str;
        }
        return str.substring(0, pos);
    }
}

Related

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