In my application, I am appending a string to create path to generate a URL. Now I want to remove that appended string on pressing back button.
Suppose this is the s
You can use org.apache.commons.lang3.StringUtils.substringBeforeLast which is null-safe.
From the javadoc:
// The symbol * is used to indicate any input including null.
StringUtils.substringBeforeLast(null, *) = null
StringUtils.substringBeforeLast("", *) = ""
StringUtils.substringBeforeLast("abcba", "b") = "abc"
StringUtils.substringBeforeLast("abc", "c") = "ab"
StringUtils.substringBeforeLast("a", "a") = ""
StringUtils.substringBeforeLast("a", "z") = "a"
StringUtils.substringBeforeLast("a", null) = "a"
StringUtils.substringBeforeLast("a", "") = "a"
Maven dependency:
org.apache.commons
commons-lang3
3.8