JS类似Java String.format的函数

String.prototype.format = String.prototype.f = function () {
var s = this,
i = arguments.length;

while (i--) {
s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]);
}
return s;
};

"chen {0} hua".format("zeng")  

 

 

posted @ 2014-05-23 10:51  天藐水瓶  阅读(771)  评论(0编辑  收藏  举报