I see a few code project solutions.
But is there a regular implementation in JavaScript?
I have defined this function:
function format() {
var args = arguments;
if (args.length <= 1) {
return args;
}
var result = args[0];
for (var i = 1; i < args.length; i++) {
result = result.replace(new RegExp("\\{" + (i - 1) + "\\}", "g"), args[i]);
}
return result;
}
And can be called like c#:
var text = format("hello {0}, your age is {1}.", "John", 29);
Result:
hello John, your age is 29.