I'm using this prototype to format strings in javascript:
String.prototype.format = function () {
var args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] != 'undefined'
? args[number]
: match
;
});
};
While it works fine, It doesn't do all I would like to do. If I have a string that is supposed to be formatted as {0:000000}, this will not fix it. How can I extend this, to add the extra 0's to my string? I can easily detect them, by fixing the regexp, but how do I format the return correctly?