string original = @"""zxc"" <[email protected]> 2005/05/11 17:48 To: <[email protected]> cc: <[email protected]> ' 孟鋼 ' <[email protected]> ""'vxcvhfdsg fdgdsfgdfs'"" <[email protected]> Subject: RE: EFS/Notes template
………………………………………………………………………………………………
请问:
    怎么样能把上面的字符串中的值给提到相应的text中MailFrom = "";  <-------发件人----"zxc"" <[email protected]>
MailTo = "";    <-------收件人-----<[email protected]>
MailCC = "";    <------cc----<[email protected]> cc: <[email protected]> ' 孟鋼 ' <[email protected]> ""'vxcvhfdsg fdgdsfgdfs'"" <[email protected]>
Subject = "";   <-------RE: EFS/Notes template
Memo = "";      <-------时间-----(Sent: 2005/05/11 17:48)"对字符串处理,最简单的应该是正则表达式吧
请问应该怎么做

解决方案 »

  1.   

    string original = @""From:"zxc"" <[email protected]> 2005/05/11 17:48 
                         To: <[email protected]
                         cc: <[email protected]> ' 孟鋼 ' <[email protected]> ""'vxcvhfdsg fdgdsfgdfs'"" <[email protected]
                         Subject: RE: EFS/Notes template
    ………………………………………………………………………………………………请问:我要是想把<>里的东西给匹配出来的正则表达式应该怎么写
    Subject = "";   <-------RE: EFS/Notes template
    Memo = "";      <-------时间-----(Sent: 2005/05/11 17:48)"
    上边那2个比较特殊
      

  2.   

    这样吧。你的原字符串格式不对吧。我改了一下。你试试吧。 static void Main()
    {
    string s = "From:zxc <[email protected]> 2005/05/11 17:48 \r\nTo: <[email protected]> \r\ncc: <[email protected]> ' 孟鋼 ' <[email protected]> \"'vxcvhfdsg fdgdsfgdfs'\" <[email protected]> \r\nSubject: RE: EFS/Notes template";
    Regex r = new Regex( "From:[ ]?[^>]*> (?<Memo>[^\\n]*) .*Subject:[ ]?(?<Subject>[^\\n]*)",RegexOptions.Singleline);
    Match m = r.Match( s);
    Console.WriteLine( "|{0}|{1}|", m.Groups["Subject"].Value,m.Groups["Memo"].Value);
    }