Skip to content

Instantly share code, notes, and snippets.

@guumaster
Created October 17, 2013 15:02
Show Gist options
  • Save guumaster/7026496 to your computer and use it in GitHub Desktop.
Save guumaster/7026496 to your computer and use it in GitHub Desktop.
quick&dirty sprintf
function format(str) {
var args = [].slice.call(arguments);
str = args.shift();
return str.replace(/%(\d+)/g,
function(match, i) {
return args[--i];
});
}
format('Name: %1\nEmail: %2', 'Eric', 'eric@example.com');
// Name: Eric
// Email: eric@example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment