Recreate C#'s String.Format

Published by Apocalypto in

Recreate C#'s String.Format where the first argument is the string template and all subsequent arguments are the values for the corresponding placeholders in the template.

Examples

String.Format("{0}{1}{2}{1}{0}",  "k",  "a", "y") ➞ "kayak"

String.Format("Palindromes are {0}", "fun") ➞ "Palindromes are fun"

String.Format("Hello {0}.\nGeneral {1}",  "there",  "Kenobi") ➞ "Hello there.\nGeneral Kenobi"

Notes

N/A

Watch a quick demo on how Edabit works.