Created
November 4, 2014 13:19
-
-
Save gabrielrubens/01751f4ab2781d20ac0b to your computer and use it in GitHub Desktop.
Formatar String em JavaScript / Format String with 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
stringFormat = function(format) { | |
var args = Array.prototype.slice.call(arguments, 1); | |
return format.replace(/{(\d+)}/g, function(match, number) { | |
return typeof args[number] != 'undefined' ? args[number] : match; | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment