Skip to content

Instantly share code, notes, and snippets.

@BrandonZacharie
Created February 21, 2012 21:17
Show Gist options
  • Save BrandonZacharie/1879011 to your computer and use it in GitHub Desktop.
Save BrandonZacharie/1879011 to your computer and use it in GitHub Desktop.
A .NET inspired String.format function in JavaScript
if (!String.format)
String.format = function String_format(value) {
if (arguments.length === 0)
return null;
for (var i = 1, l = arguments.length; i !== l; ++i)
value = value.replace(RegExp('\\{' + (i - 1) + '\\}','gm'), arguments[i]);
return value;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment