Created
April 8, 2014 20:03
-
-
Save mrpossoms/10182542 to your computer and use it in GitHub Desktop.
Convenient format strings
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
"".__proto__.format = function(params){ | |
var temp = this; | |
for(var i = params.length; i--;) | |
temp=temp.replace("{"+i+"}",params[i]); | |
return temp; | |
}; | |
// ___ _ | |
// | __|_ ____ _ _ __ _ __| |___ | |
// | _|\ \ / _` | ' \| '_ \ / -_) | |
// |___/_\_\__,_|_|_|_| .__/_\___| | |
// |_| | |
"This {0} a {1}".format(['is', 'test']); | |
// ___ _ _ | |
// | _ \___ ____ _| | |_ | |
// | / -_|_-< || | | _| | |
// |_|_\___/__/\_,_|_|\__| | |
// | |
> "This is a test" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment