format method

String format(
  1. List<Object> args
)

Formats this string using positional placeholders {0}, {1}, etc.

'Hello {0}, you are {1}!'.format(['World', 'awesome'])
// 'Hello World, you are awesome!'

Implementation

String format(List<Object> args) {
  return replaceAllMapped(RegExp(r'\{(\d+)\}'), (m) {
    final i = int.parse(m.group(1)!);
    if (i < 0 || i >= args.length) {
      throw ArgumentError(
          'Index $i out of range for args of length ${args.length}');
    }
    return args[i].toString();
  });
}