Skip to content

Instantly share code, notes, and snippets.

@aymanfarhat
Created January 6, 2013 14:31
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 aymanfarhat/4467539 to your computer and use it in GitHub Desktop.
Save aymanfarhat/4467539 to your computer and use it in GitHub Desktop.
Simple implementation of C#'s String.format() in Javascript for building strings
String.prototype.format = function()
{
var args = arguments;
return this.replace(/{(\d+)}/g, function(match, number)
{
return typeof args[number] != 'undefined'? args[number]:match;
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment