La funzione “System.String.Format” presente in dotNET è tra le più utili e fondamentali dell’ambiente. Sfortunatamente in Javascript non esiste nulla di simile. Il codice seguente consente di compensare questa lacuna.
Codice
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 ; }); }; }