C# 怎么截取符号

来源:互联网 发布:遗传算法用什么编程 编辑:程序博客网 时间:2024/06/10 07:06

 string str= "ALARM:HC1;2010-08-06 10:43:20;剑川线;T47-T80;T20-T59;900End";    

            string temp = "";
            string strALARMTYPE = "";//报警类型
            string strRecord = "";//报警级别
            string strALARMTIME = "";//报警时间
            string strLINENAME = "";//线路名
            string strSTRAINNAME = "";//耐张段
            string strSPANNAME = "";//档距段
            string strALARMVALUE = "";//报警值               

 

//得到HC1;2010-08-06 10:43:20;剑川线;T47-T80;T20-T59;900End
                    temp = str.Remove(0, str.IndexOf(":")+1);
                    strALARMTYPE = temp.Substring(0, temp.IndexOf(";")-1);//获得报警类型
                    strRecord = temp.Substring(strALARMTYPE.Length, 1);//获得报警级别

                    //2010-08-06 10:43:20;剑川线;T47-T80;T20-T59;900End
                    temp = temp.Remove(0, temp.IndexOf(";")+1);
                    strALARMTIME = temp.Substring(0,temp.IndexOf(";"));//获得报警时间

                    //剑川线;T47-T80;T20-T59;900End
                    temp = temp.Remove(0, temp.IndexOf(";") + 1);
                    strLINENAME = temp.Substring(0, temp.IndexOf(";"));//线路名

                    //T47-T80;T20-T59;900End
                    temp = temp.Remove(0,temp.IndexOf(";")+1);
                    strSTRAINNAME = temp.Substring(0, temp.IndexOf(";"));//耐张段

                    //T20-T59;900End
                    temp = temp.Remove(0, temp.IndexOf(";") + 1);
                    strSPANNAME = temp.Substring(0, temp.IndexOf(";"));//档距段

                    //900End
                    temp = temp.Remove(0, temp.IndexOf(";") + 1);
                    strALARMVALUE = temp.Substring(0, temp.IndexOf("E"));//报警值