Created
February 21, 2012 21:17
-
-
Save BrandonZacharie/1879011 to your computer and use it in GitHub Desktop.
A .NET inspired String.format function in JavaScript
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
if (!String.format) | |
String.format = function String_format(value) { | |
if (arguments.length === 0) | |
return null; | |
for (var i = 1, l = arguments.length; i !== l; ++i) | |
value = value.replace(RegExp('\\{' + (i - 1) + '\\}','gm'), arguments[i]); | |
return value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment