Skip to content

Instantly share code, notes, and snippets.

@Reizinixc
Created July 16, 2014 13:23
Show Gist options
  • Select an option

  • Save Reizinixc/e690c6f3baba497d6157 to your computer and use it in GitHub Desktop.

Select an option

Save Reizinixc/e690c6f3baba497d6157 to your computer and use it in GitHub Desktop.
C# style string formatting in JavaScript
/**
* C# style string formatting
*
* @param {...string|...Number} args
* @return {string}
*/
String.prototype.format = String.prototype.format || function() {
return [].reduce.call(arguments, function(formatted, arg, i) {
return formatted.replace('{' + i + '}', arg, 'gi');
}, this);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment