Skip to content

Instantly share code, notes, and snippets.

@mrpossoms
Created April 8, 2014 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrpossoms/10182542 to your computer and use it in GitHub Desktop.
Save mrpossoms/10182542 to your computer and use it in GitHub Desktop.
Convenient format strings
"".__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