Created
April 22, 2010 20:55
-
-
Save jbrantly/375801 to your computer and use it in GitHub Desktop.
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
var format = function(str) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
var replaceFunc = function(matchedStr) { | |
var index = parseInt(matchedStr.substring(1, matchedStr.length-1), 10); | |
return args[index] != null ? args[index] : ''; | |
}; | |
return str.replace(/\{[0-9]+\}/g, replaceFunc); | |
}; | |
format("Hello {0}", "world"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment