List of utility methods to do String Format
format()String.prototype.format = function () { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\{' + i + '\\}', 'gi'); formatted = formatted.replace(regexp, arguments[i]); return formatted; }; String.prototype.replaceAll = function (find, replace) { ... | |
format()String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function() { return args[arguments[1]]; }); }; | |
format()String.prototype.format = function () { var formatted = this; for (var prop in arguments[0]) { var regexp = new RegExp('\\{' + prop + '\\}', 'gi'); formatted = formatted.replace(regexp, arguments[0][prop]); return formatted; }; if (typeof String.prototype.trim !== 'function') { ... | |
format()String.prototype.format = function() { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\{'+i+'\\}', 'gi'); formatted = formatted.replace(regexp, arguments[i]); return formatted; }; | |
format()String.prototype.format = function() { var txt = this, i = arguments.length; while (i--) { txt = txt.replace ( new RegExp('\\{' + i + '\\}', 'gm'), arguments[i] ); return txt; }; | |
format()String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); }; | |
format()String.prototype.format = function () { var args = arguments; return this.replace(/{(\d+)}/g, function (match, number) { return typeof args[number] != 'undefined' ? args[number] : match; }); }; | |
format()String.prototype.format = function () { var str = this; for (var i = 0; i < arguments.length; i++) { var reg = new RegExp("\\{" + i + "\\}", "gm"); str = str.replace(reg, arguments[i]); return str; | |
format()String.prototype.format = function() { var args = arguments; return this.replace(/{(\d+)}/g, function(match, number) { return typeof args[number] != 'undefined' ? args[number] : match ; }); }; ... | |
format()String.prototype.format = function () { var formatted = this; for (var i = 0; i < arguments.length; i++) { formatted = formatted.replace( RegExp('\\{' + i + '\\}', 'g'), arguments[i]); return formatted; }; |