


var str = cc.formatStr(“image%02d.png”,3);
//我期望的输出 image03.png
结果输出 image%02d.png 3
坑爹啊,我查看源代码,居然只是简单的替换下%d和%s
result = str.match(/(%d)|(%s)/);
if(result){
str = str.replace(/(%d)|(%s)/, arg);
break;
}

这也叫格式化输出?放学别走…



var str = cc.formatStr(“image%02d.png”,3);
//我期望的输出 image03.png
结果输出 image%02d.png 3
坑爹啊,我查看源代码,居然只是简单的替换下%d和%s
result = str.match(/(%d)|(%s)/);
if(result){
str = str.replace(/(%d)|(%s)/, arg);
break;
}

这也叫格式化输出?放学别走…
String.prototype.format = function (){
var args = arguments;
return this.replace(/{(\d+)}/g,function(s,i){
return args*;
});
}
“{0}级,{1}已生产”.format(2,“步兵”);
会输出 2级,步兵已生产*
我想要的效果是 %02d 这样补全空缺的0的这种效果,