Skip to content

Instantly share code, notes, and snippets.

@jbrantly
Created April 22, 2010 20:55
Show Gist options
  • Save jbrantly/375801 to your computer and use it in GitHub Desktop.
Save jbrantly/375801 to your computer and use it in GitHub Desktop.
var format = function(str) {
var args = Array.prototype.slice.call(arguments, 1);
var replaceFunc = function(matchedStr) {
var index = parseInt(matchedStr.substring(1, matchedStr.length-1), 10);
return args[index] != null ? args[index] : '';
};
return str.replace(/\{[0-9]+\}/g, replaceFunc);
};
format("Hello {0}", "world");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment