Using js function in JavaScript equivalent to printf/string.format
if (!String.prototype.format) {
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
}
Trying to pass delimited fields as a parameter to this function argument. using split to create array and pass it as argument but does not seem to work
var str =" this is a {0} test in {1}";
var args = "StringFormat|Javascript";
var return = str.format(args.split("|"));
actual: this is a StringFormat|Javascript test in {1}
expected: this is a StringFormat test in Javascript