Last active
July 26, 2019 05:54
-
-
Save shaulhameed/b528d12eeab1e612cbf044f860da0f2a to your computer and use it in GitHub Desktop.
C# like String.format in Javascript
This file contains hidden or 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.format = function() { | |
var s = arguments[0]; | |
for (var i = 0; i < arguments.length - 1; i++) { | |
var reg = new RegExp("\\{" + i + "\\}", "gm"); | |
s = s.replace(reg, arguments[i + 1]); | |
} | |
return s; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment