Here you can find the source of subStringBeforeLast(String str, String separator)
Parameter | Description |
---|---|
str | string that should be analyzed |
separator | string that should separate string. Examples: subStringBeforeLast("aaaQQaQQde","QQ") = "aaaaQQ" subStringBeforeLast("aaaQQaQQde","test") = "aaaQQaQQde" |
public static String subStringBeforeLast(String str, String separator)
//package com.java2s; public class Main { /**//from w ww .j av a2 s .c o m * returns string before last entry of separator * in case string doesn't contain separator -- returns whole string * * @param str string that should be analyzed * @param separator string that should separate string. * Examples: * subStringBeforeLast("aaaQQaQQde","QQ") = "aaaaQQ" * subStringBeforeLast("aaaQQaQQde","test") = "aaaQQaQQde" */ public static String subStringBeforeLast(String str, String separator) { int from = str.lastIndexOf(separator); return from == -1 ? str : str.substring(0, from); } }