如:string a="[email protected],[email protected],[email protected],[email protected]";
int count = a.Length - a.Replace(",", String.Empty).Length;ArrayList alist = new ArrayList();
 for (int i = 0; i < count ; i++)
 {
   alist.Add(    );//不该如何写
  
 }就是截取每个email把他们加入alist中,不知道alist.Add(    );中应该怎么写。请高手指点。谢谢!

解决方案 »

  1.   

    using System.Text.RegularExpressions;
    用 正则表达式\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+
    System.Text.RegularExpressions.Regex reg; System.Collections.ArrayList ar = new System.Collections.ArrayList(); r = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+",System.Text.RegularExpressions.RegexOptions.IgnoreCase); 
    for (m = r.Match(input); m.Success; m = m.NextMatch()) 

      ar.Add(m.Groups[1].ToString()); 

      

  2.   

    只针对你说的字符串形式,若有更复杂的,请参考使用正则表达式。string a = "[email protected],[email protected],[email protected],[email protected]";
            string[] arrs = a.Split(new char[] { ',' });
            ArrayList alist = new ArrayList();
            for (int i = 0; i < arrs.Length; i++)
            {
                alist.Add()(arrs[i]);
            }
      

  3.   

    直接 string [] array =  a.Split(',') ;
    System.Text.RegularExpressions.Regex reg = new  System.Text.RegularExpressions.Regex ('匹配邮箱正则表达式') 
    foreach(string sub str in array)
    {
          //判断Email是否合法,合法的添加到ArrayList中
         if(reg......)
        {
     ....
    }    }
      

  4.   


                string text = "[email protected],[email protected],[email protected],[email protected]";
                string pat = @"(\w+@\w+\.com)";
                ArrayList alist = new ArrayList();             Regex r = new Regex(pat, RegexOptions.IgnoreCase);
                Match m = r.Match(text);
                for (m = r.Match(text); m.Success; m.NextMatch())
                {
                    alist.Add(m.Groups[1].Value);
                }
      

  5.   

    这个用正则是不是大材小用了.呵.
    建议不要使用ArrayList这是一个弱类型的对象.除非ArrayList中的数据类型不能确定.可以直接使用一个数组. string a = "[email protected],[email protected],[email protected],[email protected]";
     string[] emailCollection = a.Split(',');
      

  6.   

    using System.Text.RegularExpressions; 
    如:string a="[email protected],[email protected],[email protected],[email protected]"; 
    string[] email=Regex.Split(",", a);
    ArrayList alist = new ArrayList();
    for (int i = 0; i < email.Length; i++)
    {
      alist.Add(email[i]);