c#和JS字符串format实现(可实现JSON对象,c#实体对象,C#匿名对象,替换)
2021-05-20 08:27
标签:new cti key java 自己 调用 ref ret sum javascript调用: 2.C#后台实现代码,下面方法自己写的; c#调用方法: c#和JS字符串format实现(可实现JSON对象,c#实体对象,C#匿名对象,替换) 标签:new cti key java 自己 调用 ref ret sum 原文地址:https://blog.51cto.com/317057112/2427053String.prototype.format= function () {
if (arguments.length == 0) return this;
var param = arguments[0];
var s = this;
if (typeof (param) == ‘object‘) {
for (var key in param)
s = s.replace(new RegExp("\\{" + key + "\\}", "g"), param[key]);
return s;
} else {
for (var i = 0; i
var str = "js实现用{two}自符串替换占位符{two} {three} {one} ".format({one: "I",two: "LOVE",three: "YOU"});
var str2 = "js实现用{1}自符串替换占位符{1} {2} {0} ".format("I","LOVE","YOU");
///
string ssew = "{one:‘I‘,two: ‘LOVE‘,three: ‘YOU‘}";
Newtonsoft.Json.Linq.JObject o2 = Newtonsoft.Json.Linq.JObject.Parse(ssew);
string sew = CommonFunc.Format("{ONE} {TWO} {three} ", o2);
var ste = new { one = "I", two = "LOVE", three = "You" };
string ese = CommonFunc.Format("{ONE} {TWO} {three} ", ste);
文章标题:c#和JS字符串format实现(可实现JSON对象,c#实体对象,C#匿名对象,替换)
文章链接:http://soscw.com/index.php/essay/87879.html