Skip to content

Instantly share code, notes, and snippets.

@vampireneo
Created November 26, 2012 05:59
Show Gist options
  • Save vampireneo/4146791 to your computer and use it in GitHub Desktop.
Save vampireneo/4146791 to your computer and use it in GitHub Desktop.
string.format function
String.prototype.format = function() {
var str = this;
for (var i = 0; i <= arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
str = str.replace(reg, arguments[i]);
}
return str;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment