http://js.jirengu.com/zemu/1/edit?html,js,console,output
function stringFormat(string){
var params = [].slice.call(arguments,1);
var regxp = /\{(\d+)\}/g;
string= string.replace(regxp,function(){
var index=arguments[1];
return params[index];
});
return string;
}
console.log(stringFormat('Hi, {0}', 'nsxz'));//第一个参数为待处理字符串
console.log(stringFormat('Hi, {0}', 'nsxz','Xiaoming'));
网友评论