In Java we have indexOf
and lastIndexOf
. Is there anything like lastSubstring
? It should work like :
"aaple".lastSubstring(0, 1) = "e";
Not in the standard Java API, but ...
Apache Commons has a lot of handy String helper methods in StringUtils
... including StringUtils.right("apple",1)
http://commons.apache.org/lang/api/org/apache/commons/lang/StringUtils.html#right(java.lang.String,%20int)
just grab a copy of commons-lang.jar from commons.apache.org
Generalizing the other responses, you can implement lastSubstring as follows:
s.substring(s.length()-endIndex,s.length()-beginIndex);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With