Skip to content

Instantly share code, notes, and snippets.

@tonyto
Created July 28, 2011 16:51
Show Gist options
  • Save tonyto/1111926 to your computer and use it in GitHub Desktop.
Save tonyto/1111926 to your computer and use it in GitHub Desktop.
javascript string format
String.prototype.format = function() {
var formatted = this;
for (var i = 0; i < arguments.length; i++) {
var regexp = new RegExp('\\{'+i+'\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment