introduction
String.Format used to C#. Today, I saw that other people's code also encapsulates a js String.Format in js, which is used to splice strings and DOM.
js implementation and calling String.Format
String.Format = function (str) { for (var i = 1; i < arguments.length; i++) { var parent = "//{" + (i - 1) + "//}"; var reg = new RegExp(parent, "g") str = str.replace(reg, arguments[i]); } return str;} string.Format("<span>Your answer is: <b>{0}</b></span>", remark);str += string.Format(temp, data[i].Item2, data[i].Item1);
The above example code for implementing String.Fomat in js is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.