Skip to content

Instantly share code, notes, and snippets.

@mcheck
Created January 15, 2013 21:56
Show Gist options
  • Save mcheck/4542499 to your computer and use it in GitHub Desktop.
Save mcheck/4542499 to your computer and use it in GitHub Desktop.
javascript string interpolation ... sort of
// javascript string interpolation
// simple string builder- usage: stringFormat("Hello {0}","world");
// returns "Hello world"
function stringFormat() {
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