实现这个方法,是因为我太习惯cSharp里的String.Format方法。这个自然没有它功能强大,仅仅实现按照参数和格式序号简单替换。

String.prototype.format = function(){
	if(arguments.length == 0) return this;
	var _this = this, i = 0, matches = _this.match(/{\d+}/g), l = Math.min(arguments.length, matches.length), _i, _s;
	if(matches.length == 0){
		_this = null; i = null; matches = null; l = null; _i = null; _s = null;
		return this;
	}
	for(; i < l; i++)
		if(!isNaN(_i = parseInt((_s = matches[i] + '').substr(1))))
			_this = _this.replace(_s, arguments[_i] + '');
	i = null; matches = null; l = null; _i = null; _s = null;
	return _this;
}

相关文章:

  • 2022-02-08
  • 2021-12-30
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-16
  • 2021-08-18
猜你喜欢
  • 2022-12-23
  • 2021-12-06
  • 2021-10-14
  • 2022-12-23
  • 2021-05-18
  • 2021-12-30
  • 2021-05-28
相关资源
相似解决方案