首页 > Windows开发 > 详细

C# 字符串的操作

时间:2019-03-27 13:05:24      阅读:147      评论:0      收藏:0      [点我收藏+]
技术分享图片
      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# 字符串的操作

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!