开发者

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

开发者 https://www.devze.com 2023-03-05 10:24 出处:网络
This question already has answers here: Equivalent of String.format in jQuery (22 answers) 开发者_JAVA技巧Closed 9 years ago.
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

精彩评论

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

关注公众号