/ Published in: JavaScript
Example:
var result = "Hello {0}! This is {1}.".format("world","foo bar");
Returns:
"Hello World! This is foo bar."
Expand |
Embed | Plain Text
String.prototype.format = function(){ var pattern = /\{\d+\}/g; var args = arguments; return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; }); }
You need to login to post a comment.
