Python has this beautiful function to turn this:
bar1 = \'foobar\'
bar2 = \'jumped\'
bar3 = \'dog\'
foo = \'The lazy \' + bar3 + \' \' + bar2 \' over the \'
Taken from YAHOOs library:
YAHOO.Tools.printf = function() {
var num = arguments.length;
var oStr = arguments[0];
for (var i = 1; i < num; i++) {
var pattern = "\\{" + (i-1) + "\\}";
var re = new RegExp(pattern, "g");
oStr = oStr.replace(re, arguments[i]);
}
return oStr;
}
Call it like:
bar1 = 'foobar'
bar2 = 'jumped'
bar3 = 'dog'
foo = YAHOO.Tools.printf('The lazy {0} {1} over the {2}', bar3, bar2, bar1);