If I have a String:
String neatish = getTheString(); // returns "...neat..."
I know that I can get rid of the first ellipsis using:
getTheString().substring(3);
But I'm wondering if there's a similar one-line method that takes the end off, based on length? Like:
getTheString().substring(3).truncate(3);
I don't want a character-specific method, ie. one that works only on ellipses.
While there's a substring()
that accepts two parameters, it requires the altering String
to be saved off to a variable first to determine the length. (Or, you can call getTheString()
twice.)
I can certainly write one, but I'm wondering if there is a one-line method either in the standard java.lang
package, or in Apache Commons-Lang, that will accomplish this.
I'm 50% curious, and 50% avoiding re-inventing the wheel.
Update: To avoid confusion, I do not want:
String neatish = getTheString();
neatish = neatish.substring(3)...;
I'm instead looking for the back-end version of substring()
, and wondering why there isn't one.