Created
November 26, 2012 05:59
-
-
Save vampireneo/4146791 to your computer and use it in GitHub Desktop.
string.format function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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