Jan 20
Perl does this very well, other language less so. Less is a hybrid of the C# method for string formatting. I find it pretty convenient when creating a lot of dynamic html to insert using that oh so hander innerHTML property. Remember, innerHTML is usually the fastest way to add dynamic html.
Updated JavaScript String Interpolation (Formatting) Function
Interpolation is just a fancy word for variable substitutioin in a string.According to the free dictionary interpolate means:1. To insert or introduce between other elements or parts.
2. a. To insert (material) into a text.
Perl does this very well, other language less so. Less is a hybrid of the C# method for string formatting. I find it pretty convenient when creating a lot of dynamic html to insert using that oh so hander innerHTML property. Remember, innerHTML is usually the fastest way to add dynamic html.
function format(format) {
var params = arguments;
var toReturn = format; for (var i = 0; i < params.length - 1; i++) {
var rString = '\\$\\{' + (i) + '\\}';
var regex = new RegExp(rString, "g");
toReturn = toReturn.replace(regex, params[i + 1]);
} return toReturn;
}
