&BILLHEAD6025|20060509|20060509
13700000000|602502|20060511|1500|1
......
&BILLTAIL6025|16
&OUTHEAD6025|20060509|20060509
139000000|602507|20060509|5
......
&OUTTAIL6025|2
我有一段这样的内容,现在需要分开提取BILL项中内容和OUT项中的内容.BILL、OUT标签行的数字是会变动的,提取内容时不需要标签行内容.应该怎样取.在线等待........

解决方案 »

  1.   

    可以直接以| 为分界点 用substring来截取
      

  2.   

    获得某个字符串在另个字符串第一次出现时前面所有字符
    public static string GetFirstStr(string strOriginal,string strSymbol)
    {
    int strPlace=strOriginal.IndexOf(strSymbol);
    if (strPlace!=-1)
    strOriginal=strOriginal.Substring(0,strPlace);
    return strOriginal;
    }
    用这个一项一项拆
      

  3.   

    [\&BILL|\&OUT][a-zA-Z]{4}(?<mytag>(\d+|\d*)*)
      

  4.   

    StringCollection GetLabels(string text)
    {
     string s = "&(BILL|OUT)(?<Label>[^&]*)";
     StringCollection lables = new StringCollection(); MatchCollection matches = Regex.Matches(text, s); foreach(Match match in matches)
     {
      lables.Add(match.Group("Label").Text);
     }
     return labels;
    }
      

  5.   

    测试数据:
    &BILLHEAD6025|20060509|20060509
    13700000000|602502|20060511|1500|1
    &BILLTAIL6025|16&OUTHEAD6025|20060509|20060509
    139000000|602507|20060509|5&OUTTAIL6025|2表达式:[\&BILL][A-Z]{4}(?<mytag>[\d+\|\d*\n*\r*]*)结果:
    6025|20060509|20060509
    13700000000|602502|20060511|1500|16025|16表达式:[\&OUT][A-Z]{4}(?<mytag>[\d+\|\d*\n*\r*]*)结果:
    6025|20060509|20060509
    139000000|602507|20060509|56025|2测试器
    http://birdshover.cnblogs.com/archive/2006/05/10/396844.html
      

  6.   

    (?<=BILL.*)[\S\s]*(?=BILL.*)
    (?<=OUT.*)[\S\s]*(?=OUT.*)