Search code examples
guavaapache-commonsapache-commons-lang

What is the Guava equivalent to StringUtils.removeEnd?


I struggle to find a Guava equivalent for commons-lang StringUtils.removeEnd. Is there such a method or do I have to use a Joiner and a Splitter in some way?


Solution

  • I don't think Guava provides such a method, but it's a trivial one-liner:

    s = s.endsWith(suffix) ? s.substring(0, s.length() - suffix.length()) : s;