This is driving me nuts. I believe I asked this exact same question, but I can\'t find it any more (I used Stack Overflow search, Google Search, manually searched my po
String.prototype.format = function () {
var formatted = this;
for (var arg in arguments) {
formatted = formatted.split('{' + arg + '}').join(arguments[arg]);
}
return formatted;
};
USAGE:
'Hello {0}!'.format('Word')
->
Hello World!
'He{0}{0}o World!'.format('l')
->
Hello World!
'{0} {1}!'.format('Hello', 'Word')
->
Hello World!
'{0}!'.format('Hello {1}', 'Word')
->
Hello World!