Skip to content

Instantly share code, notes, and snippets.

@Foodguru
Forked from tonyto/stringFormat.js
Created November 3, 2012 12:43
Show Gist options
  • Save Foodguru/4007261 to your computer and use it in GitHub Desktop.
Save Foodguru/4007261 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