需要对字符串做解析,字符串格式如下:
[Error] MainFrm.cs(30) Internal Error: Incapable type 'string' and 'char'需要得到的字符串数组:
Error
MainFrm.cs
30
Internal Error: Incapable type 'string' and 'char'请各位大侠帮帮忙,谢谢!

解决方案 »

  1.   

    \[([^]]*\)]\s*([a-z\.0-9]*)\(([^\)]*)\)\s*(.*)
      

  2.   

    上面错了:
    (?i)\[([^]]*)\]\s*([a-z\.0-9]*)\s*\(([^\)]*)\)(.*)
      

  3.   

    Regex reg=new Regex(@"(?i)\[([^]]*)\]\s*([a-z\.0-9]*)\s*\(([^\)]*)\)(.*)");
    ArrayList list=new ArrayList();
    Match m=reg.Match("你的字符串");
    list.Add(m.Group[1].Value);
    list.Add(m.Group[2].Value);
    list.Add(m.Group[3].Value);
    list.Add(m.Group[4].Value);
    楼主要的是这个吗?
      

  4.   

    是的,多谢兄台相助。
    我的意图是将文本文件中的这类信息提取到xml文件中。但试了上面的代码好像不行。文本文件中的行:
    [Error] MainFrm.pas(30): Invalid type capable: string and pansicharxml的格式如下:
      <?xml version="1.0" encoding="utf-8" ?> 
      <Info>
          <Message Type="Error">
            <FileName>MainFrm.pas</FileName> 
            <LineNo>30</LineNo> 
            <MsgInfo>Invalid type capable: string and pansichar</MsgInfo> 
          </Message>
      </Info>
    因此,从文本文件中读取行后进行分析,然后将信息写到xml文件中来上面那个[Error] MainFrm.pas(30): Invalid type capable: string and pansichar都有空格。
      

  5.   

    怎么不行呢?
    如果是有很多类似的信息的话,要用:
    Regex reg=new Regex(@"(?i)\[([^]]*)\]\s*([a-z\.0-9]*)\s*\(([^\)]*)\)\s*:\s*(.*)");
    ArrayList list=new ArrayList();
    foreach(Match m in reg.Matchs("你的字符串"))
    {
    list.Add(m.Group[1].Value);
    list.Add(m.Group[2].Value);
    list.Add(m.Group[3].Value);
    list.Add(m.Group[4].Value);
    }