I ended up writing my own function, this might help someone:
static String replaceString(String source, String toReplace, String replaceWith) { if (source == null || source.length() == 0 || toReplace == null || toReplace.length() == 0) return source; int index = source.indexOf(toReplace); if (index == -1) return source; String replacement = (replaceWith == null) ? "" : replaceWith; String replaced = source.substring(0, index) + replacement + source.substring(index + toReplace.length()); return replaced; }
and then I just call it 3 times:
String replaced = replaceString("This string contains placeholders %s %s %s", "%s", "first"); replaced = replaceString(replaced, "%s", "second"); replaced = replaceString(replaced, "%s", "third");
source share