JavaScript String format
Here’s a useful snippet of JavaScript I use for inserting arguments into a format string:
String.format = function()
{
var replacements = arguments;
return arguments[0].replace(/\{(\d+)\}/gm, function(string, match) {
return replacements[parseInt(match) + 1];
});
}And here it is in action:
String.format('http://www.google.com/search?q={0}', escape(searchTerm))