format method

String format(
  1. List replacements
)

Replace string pattern consecutively. Patterns are marked with double-curly brackets.

Example:

var template = "My name is {{name}} and I'm {{age}} years old"
sprintf(template, ['Oval', 17]);

Result:

"My name is Oval and I'm 17 years old"

Implementation

String format(List replacements) {
  var template = this;
  var regExp = RegExp(placeholderPattern);
  assert(regExp.allMatches(template).length == replacements.length,
      "Template and Replacements length are incompatible");

  for (var replacement in replacements) {
    template = template.replaceFirst(regExp, replacement.toString());
  }

  return template;
}