Java{0}占位符替换字符串 public class Test { public static void main(String[] args) { System.out.println(String.format("http://www.{0}.com", "baidu"));//错误的 System.out.println(String.format("http://www.%s.com", "baidu"));//%…
String.prototype.format=function(){ if(arguments.length===0){ return String(this); } let reg=/(\{\d\})/; let r=this; while(reg.test(r)){ let index=RegExp.$1.slice(1,-1); r = r.replace(new RegExp("\\{"+index+"\\}","g"),(index…