C# 字符串的操作

2021-06-10 11:05

阅读:350

标签:[]   replace   col   none   sage   lse   string   stat   opened   

技术图片技术图片
      var tStr = "0|1:开门|2:关门|3:门检失败|4:开门|5:开门|6:关门";
            var result = string.Format("[{0}]", string.Join(",", tStr.Substring(2).Split(|).Select(s => string.Format("{{doorid:{0}, status:{1}}}", s.Split(:)[0], s.Split(:)[1]).Replace("开门", "1").Replace("关门", "0").Replace("门检失败", "-1")).ToArray()));
            MessageBox.Show(result);
            //string  tStr = "0|1:开门|2:关门|3:门检失败|4:开门|5:开门|6:关门";
            //tStr = tStr.Replace(":", ",");
            //tStr = tStr.Replace("开门", "status:1}");
            //tStr = tStr.Replace("关门", "status:0}");
            //tStr = tStr.Replace("门检失败", "status:-1}");
            ////tStr = tStr.Replace("|", "{doorid:");

            //string[] str = tStr.Split(‘|‘);
            //string strs = "[";

            //for (int i = 1; i //{
            //    MessageBox.Show(i.ToString());
            //    if (i //    {
            //        strs += "{doorid:" + str[i] + ",";
            //    } else if( i== str.Length - 1)
            //    {
            //        strs += "{doorid:" + str[i] + "]";
            //    }
            //}
            //MessageBox.Show(strs);
View Code

 

C# 字符串的操作

标签:[]   replace   col   none   sage   lse   string   stat   opened   

原文地址:https://www.cnblogs.com/aijiao/p/10606661.html


评论


亲,登录后才可以留言!