Here you can find the source of format(args)
// FUNCION: {String}.format() --> similar to C#.NET // Sample usage://from w ww . jav a2s . c om // var haha = "She {1} {0}{2} by the {0}{3}. {-1}^_^{-2}"; // str = haha.format(["sea", "sells", "shells", "shore"]); String.prototype.format = function (args) { var str = this; return str.replace(String.prototype.format.regex, function(item) { var intVal = parseInt(item.substring(1, item.length - 1)); var replace; if (intVal >= 0) { replace = args[intVal]; } else if (intVal === -1) { replace = "{"; } else if (intVal === -2) { replace = "}"; } else { replace = ""; } return replace; }); }; String.prototype.format.regex = new RegExp("{-?[0-9]+}", "g"); // end of String.format()
String.prototype.format = function (args) { var str = this; return str.replace(String.prototype.format.regex, function(item) { var intVal = parseInt(item.substring(1, item.length - 1)); var replace; if (intVal >= 0) { replace = args[intVal]; } else if (intVal === -1) { replace = "{"; ...
String.prototype.format = function(args) { if (arguments.length>0) { var result = this; if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { var reg=new RegExp ("({"+key+"})","g"); result = result.replace(reg, args[key]); } else { ...
'use strict'; String.prototype.format = function (args) { var str = this; return str.replace(String.prototype.format.regex, function(item) { var intVal = parseInt(item.substring(1, item.length - 1)); var replace; if (intVal >= 0) { replace = args[intVal]; } else if (intVal === -1) { ...
String.prototype.format = function (args) { 'use strict'; var str = this; return str.replace(String.prototype.format.regex, function (item) { var intVal = parseInt(item.substring(1, item.length - 1)); var replace; if (intVal >= 0) { replace = args[intVal]; } else if (intVal === -1) { ...
String.prototype.format = function(args) { var result = this; if (arguments.length < 1) { return result; var data = arguments; if (arguments.length == 1 && typeof (args) == "object") { data = args; for ( var key in data) { var value = data[key]; if (undefined != value) { result = result.replaceAll("\\{" + key + "\\}", value); return result;
'use strict'; String.prototype.format = function (args) { if (arguments.length > 0) { var result = this; if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { result = result.replace(new RegExp("({" + key + "})", "g"), args[key]); else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] == undefined) { return ""; else { var reg = new RegExp("({[" + i + "]})", "g"); result = result.replace(reg, arguments[i]); return result; else { return this; };
String.prototype.format = function(args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if(args[key]!=undefined){ var reg = new RegExp("({" + key + "})", "g"); result = result.replace(reg, args[key]); else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { var reg = new RegExp("({[" + i + "]})", "g"); result = result.replace(reg, arguments[i]); return result;
String.prototype.format = function (args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if (args[key] != undefined) { var reg = new RegExp("({" + key + "})", "g"); result = result.replace(reg, args[key]); else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { var reg = new RegExp("({)" + i + "(})", "g"); result = result.replace(reg, arguments[i]); return result;
String.prototype.format = function(args) { var result = this; if (arguments.length > 0) { if (arguments.length == 1 && typeof (args) == "object") { for (var key in args) { if(args[key]!=undefined){ var reg = new RegExp("({" + key + "})", "g"); result = result.replace(reg, args[key]); else { for (var i = 0; i < arguments.length; i++) { if (arguments[i] != undefined) { var reg = new RegExp("({[" + i + "]})", "g"); result = result.replace(reg, arguments[i]); return result;