Skip to content

Instantly share code, notes, and snippets.

@shaulhameed
Last active July 26, 2019 05:54
Show Gist options
  • Save shaulhameed/b528d12eeab1e612cbf044f860da0f2a to your computer and use it in GitHub Desktop.
Save shaulhameed/b528d12eeab1e612cbf044f860da0f2a to your computer and use it in GitHub Desktop.
C# like String.format in Javascript
String.format = function() {
var s = arguments[0];
for (var i = 0; i < arguments.length - 1; i++) {
var reg = new RegExp("\\{" + i + "\\}", "gm");
s = s.replace(reg, arguments[i + 1]);
}
return s;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment