I'll explain myself, I would want to add a replaceLast into String class, is that possible? At the moment I'm using a self-made method, which is:
public static String replaceLast(String string, String toReplace, String replacement) {
int pos = string.lastIndexOf(toReplace);
if (pos > -1) {
return string.substring(0, pos) + replacement + string.substring(pos + toReplace.length(), string.length());
} else {
return string;
}
}
Is there any way to be able to use this method like:
String str = "Hello World";
str.replaceLast("l", "");
//being the first String the one to be replaced and the second one the replacement
like it is used:
String str = "Hello World";
str.replaceFirst("o", "e");