码迷,mamicode.com
首页 > Windows程序 > 详细

C# 字符串的操作

时间:2019-03-27 12:38:48      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:[]   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 < str.Length; i++)
            //{
            //    MessageBox.Show(i.ToString());
            //    if (i < str.Length-1)
            //    {
            //        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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!