Here you can find the source of format()
String.prototype.format=function(){ if(arguments.length==0) return this; //from w w w .ja va2 s . co m var args=[], i=0; for(;i<arguments.length;i++) args[i]=arguments[i]; return this.replace(/\%[sSfdDTt\%]/g, function(m){ if(m=='%%') return '%'; var v=args.shift(); switch(m.substr(1,1)){ case 's': return v.toString(); case 'S': return "'"+v.replace("'","\\'")+"'"; case 'f': return v-0; case 'd': return v.getFullYear()+'-'+v.getMonth()+'-'+v.getDate(); case 'D': return v.getMonth()+'-'+v.getDate(); case 't': return v.getHours()+'-'+v.getMinutes()+'-'+v.getSeconds(); case 't': return v.getHours()+'-'+v.getMinutes(); } }); } String.prototype.removeFromList=function(c){ var arr=this.split(c), i=1; for(;i<arguments.length;i++) delete arr[arguments[i]-1]; return arr.filter(function(v){return v!==undefined}).join(c); } String.prototype.replaceList=function(c,i,s){ s=s||','; var ret=this.split(s); ret[i-1]=c; return ret.join(s); } String.prototype.reverse=function(){ return this.split("").reverse().join(""); }
String.format = function () { var s = arguments[0]; for (var i = 0; i < arguments.length - 1; i++) { var reg = new RegExp("\\{" + i + "\\}", "gm"); s = s.replace(reg, arguments[i + 1]); return s; String.prototype.format = function () { ...
String.prototype.format = function () { var args = arguments; var reg = /\{(\d+)}/g; return this.replace(reg, function (g0, g1) { return args[+g1]; }); }; var str = "this is :{0} and {1} , and {0}".format("arg1","arg2") var main = "Scripts/main"; ...
String.prototype.format = function(){ var re_all = /{(\d+)?(:(\d+)?(.\d+?f))?}/g; var re_index = /(\d+):/; var re_before = /(\d+)\./; var re_after = /\.(\d+)/; var cur = this; var matches = cur.match(re_all); if (arguments.length > matches){ console.log("Too many arguments!"); ...
String.prototype.format = function() { var txt = this; var i = arguments.length; var replaceTokens = function(txt, key, value) { return txt.replace(new RegExp('\\{' + key + '\\}', 'gm'), value); }; if(i > 0 && typeof(arguments[0]) == "object") { for(var key in arguments[0]) { txt = replaceTokens(txt, key, arguments[0][key]); ...
String.prototype.format = function() { var s = this, i = arguments.length; while (i--) { s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); return s; };
String.prototype.format=function(){ if(arguments.length==0) return this; var args=[], i=0; for(;i<arguments.length;i++) args[i]=arguments[i]; return this.replace(/\%[sSfdDTt\%]/g, function(m){ if(m=='%%') return '%'; var v=args.shift(); switch(m.substr(1,1)){ case 's': return v.toString(); ...
String.prototype.format = function (){ var values = [].slice.call(arguments, 0, arguments.length), idx, length = values.length, regex, str = this; if(str.match(/\{\d+\}/g).length !== length){ throw{ name: 'ArgumentMissMatch', ...
'use strict'; String.prototype.format = function () { var args = arguments; var unkeyed_index = 0; return this.replace(/\{{1,2}(\w*)\}{1,2}/g, function (match, key) { if (match.indexOf('{{') !== -1) { return match.replace('{{', '{').replace('}}', '}'); if (key === '') { ...
String.prototype.format = function() { var newStr = this, i = 0; while (/%s/.test(newStr)) { newStr = newStr.replace("%s", arguments[i++]) return newStr;