Created
June 16, 2014 22:56
-
-
Save drgarcia1986/dab86626da5e20fbc81e to your computer and use it in GitHub Desktop.
Habilitando método "Format" para 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
String.prototype.format = function() { | |
var formatted = this; | |
for (var i = 0; i < arguments.length; i++) { | |
var regexp = new RegExp('\\{'+i+'\\}', 'gi'); | |
formatted = formatted.replace(regexp, arguments[i]); | |
} | |
return formatted; | |
}; | |
var txt = "Nome: {0} | Sobrenome: {1}".format("Diego", "Garcia"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment