比如有这样一个字符串:
"CES2321,A320,M,ZLXY,13:15,,ZGDY,14:35,,,,W/Z,#ZLXY,1315,S0000,*,#P165,1405,S0900,EW,#DYG,1408,S0900,EW,"
我现在要取出所有"#"与","之间的字符串,以及后面的四位数据,比如例子中,我要取出的是ZLXY,然后是1315,接着取出P165,然后是1405,然后是DYG,接着是1408.请问怎么办?

解决方案 »

  1.   

    手头没有.NET环境,凭记忆写了一下,大概是这样的:
    string s = "CES2321,A320,M,ZLXY,13:15,,ZGDY,14:35,,,,W/Z,#ZLXY,1315,S0000,*,#P165,1405,S0900,EW,#DYG,1408,S0900,EW,";
    Match m = Regex.Match(s, @"#(.*?),(\d{4})");
    while (m.Success)
    {
      string s1 = m.Groups[0];
      string s2 = m.Groups[1];
      Console.WriteLine("{0}: {1}", s1, s2);
      m = m.NextMatch();
    }
      

  2.   


    string yy="CES2321,A320,M,ZLXY,13:15,,ZGDY,14:35,,,,W/Z,#ZLXY,1315,S0000,*,#P165,1405,S0900,EW,#DYG,1408,S0900,EW,";
    string y1=Regex.Match(yy,@"#(\w+),(\d+)").Result("$1");//"#"与","之间的字符串
    string y2=Regex.Match(yy,@"#(\w+),(\d+)").Result("$2");//后面的四位数据
      

  3.   

    我想应该是:
      string s1 = m.Groups[0].Value;
      string s2 = m.Groups[1].Value;
      

  4.   

    string str = "CES2321,A320,M,ZLXY,13:15,,ZGDY,14:35,,,,W/Z,#ZLXY,1315,S0000,*,#P165,1405,S0900,EW,#DYG,1408,S0900,EW,";
            Regex reg = new Regex("#(\\w+),(\\d+)");
            MatchCollection matchs = reg.Matches(str);
            foreach (Match m in matchs)
            {
                Response.Write(m.Groups[1] + ":" + m.Groups[2] + "<br />");
            }
      

  5.   

    wuyi808的可以,比我写的多了循环
    就是要稍微修改写
      string s1 = m.Groups[1].Value;
      string s2 = m.Groups[2].Value;
      

  6.   

    先用SPLIT() 拆分再SUBSTRING截取,最后连接起来就可以啦