/*
* implementation of String.replaceLast.
+ * Replaces only the last occurrence of toReplace in string with replacement.
*/
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());
+ return new StringBuilder().append(string.substring(0, pos))
+ .append(replacement)
+ .append(string.substring(pos + toReplace.length()))
+ .toString();
}
else
{