String.prototype.format
(创建时间:2010年10月20日 19:24:00)
Jangogo :

//V1 method String.prototype.format = function() { var args = arguments; return this.replace(/\{(\d+)\}/g, function(m,i){ return args; }); } //V2 static String.format = function() { if( arguments.length == 0 ) return null; var str = arguments[0]; for(var i=1;i<arguments.length;i++) { var re = new RegExp('\\{' + (i-1) + '\\}','gm'); str = str.replace(re, arguments); } return str; } var a = "I Love {0}, and You Love {1},Where are {0}! {4}"; alert(String.format(a, "You","Me")); alert(a.format("You","Me"));
文档中心