replaceTemplate function
Implementation
String replaceTemplate(String template, List<Object> params) {
int matchIndex = 0;
String replace(Match m) {
if (matchIndex < params.length) {
switch (m[0]) {
case "%s":
return params[matchIndex++].toString();
}
} else {
throw Exception("Missing parameter for string format");
}
throw Exception("Invalid format string: " + m[0].toString());
}
return template.replaceAllMapped("%s", replace);
}