开发者

C#-like String.Format() function in JQuery? [duplicate]

This question already has answers here: Equivalent of String.format in jQuery (22 answers) 开发者_JAVA技巧 Closed 9 years ago.

Is it possible to call a C#-like String.Format() function in JQuery?


Equivalent of String.format in JQuery

Here is the format function...

String.format = function() {
  var s = arguments[0];
  for (var i = 0; i < arguments.length - 1; i++) {       
    var reg = new RegExp("\\{" + i + "\\}", "gm");             
    s = s.replace(reg, arguments[i + 1]);
  }

  return s;
}


Checkout format() that's part of the validation plugin that does C# like string formatting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜