本帖最后由 subxli 于 2010-06-12 17:00:41 编辑

解决方案 »

  1.   

     string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>"+
                            "To: <[email protected]>"+
                            "Cc: 'yy'"+
                            "Subject: oo";
    如果你的From: =?gb2312?B?ztK+zcrHyfE=?= 这一节是死的,那么你可以用
    sb.indexOf("From: =?gb2312?B?ztK+zcrHyfE=?= <")获取一个值假设为xx。
    让后sb.subString(xx,17)来获取[email protected]。获取[email protected] 也可以这样实现!
    希望对你有帮助
      

  2.   

                string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>" +
                            "To: <[email protected]>" +
                            "Cc: 'yy'" +
                            "Subject: oo";            MatchCollection s = Regex.Matches(sb,  @"(?<EmailStr>\b[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}\b)", RegexOptions.IgnoreCase);
                foreach (Match m in s)
                {
                    Console.WriteLine(m.Value);
                }
                Console.Read();
      

  3.   

    string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>" +
                            "To: <[email protected]>" +
                            "Cc: 'yy'" +
                            "Subject: oo";             
    string send = sb.Split('<', '>')[1];
    string forms = sb.Split('<', '>')[3];
      

  4.   

    string send = sb.Substring(sb.IndexOf("<",0) + 1, sb.IndexOf(">") - sb.IndexOf("<",0)-1);
    string froms = sb.Substring(sb.IndexOf("<", sb.IndexOf("<", 0) + 1) + 1, sb.IndexOf(">", 0) - sb.IndexOf("<", 0));
      

  5.   

                string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>"+
                            "To: <[email protected]>"+
                            "Cc: 'yy'"+
                            "Subject: oo";可以用replace()
    剩余 <A> to: <B>string send = sb.Split('to:')[0];
    .......
      

  6.   

    先找到"From:",剪了。
    再找到"To:"的index,把之前的串读出来,剪了。 
    再找到"Cc:"的index,把之前的串读出来,剪了。 
    以此类推。比较笨的方法。
      

  7.   

    private static void TestRegex31()
    {
        string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>" +
            "To: <[email protected]>" +
            "Cc: 'yy'" +
            "Subject: oo";
        MatchCollection mc = Regex.Matches(sb, @"(?<=<)[^>]+");
        string send = mc[0].Value;   //需要取到   [email protected] 
        string froms = mc[1].Value;   //需要取到   [email protected] 
    }
      

  8.   


    请问下 Regex.Matches(sb, @"(?<=<)[^>]+"); 是什么意思?特别是"(?<=<)[^>]+"这里
      

  9.   

    正则表达式
    找到<开始,不匹配<,吧后面的非>的内容匹配出来。测试的结果如何。
      

  10.   


    测试是正确的啊 ,可是我不保证只有<>这个,万一它字符串后面又有个呢 ,如 :
                string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>" +
                            "To: <[email protected]>" +
                            "Cc: 'yy'" +
                            "Subject: oo" +
                            "content : <[email protected]>";
      

  11.   

    private static void TestRegex31()
    {
        string sb = "From: =?gb2312?B?ztK+zcrHyfE=?= <[email protected]>" +
            "To: <[email protected]>" +
            "Cc: 'yy'" +
            "Subject: oo";
        Match m = Regex.Match(sb, @"(?i)from[^<]*<(?<from>[^>]+).+?to[^<]*<(?<send>[^>]+)");
        string send = m.Groups["from"].Value;   //需要取到   [email protected] 
        string froms = m.Groups["send"].Value;   //需要取到   [email protected] 
        Console.WriteLine("send:" + send);
        Console.WriteLine("from:" + froms);
    }
      

  12.   


    这样就可以确定是From:  里 和 To: 里的 邮箱了吗?