如: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( );中应该怎么写。请高手指点。谢谢!
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( );中应该怎么写。请高手指点。谢谢!
用 正则表达式\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());
}
string[] arrs = a.Split(new char[] { ',' });
ArrayList alist = new ArrayList();
for (int i = 0; i < arrs.Length; i++)
{
alist.Add()(arrs[i]);
}
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex ('匹配邮箱正则表达式')
foreach(string sub str in array)
{
//判断Email是否合法,合法的添加到ArrayList中
if(reg......)
{
....
} }
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);
}
建议不要使用ArrayList这是一个弱类型的对象.除非ArrayList中的数据类型不能确定.可以直接使用一个数组. string a = "[email protected],[email protected],[email protected],[email protected]";
string[] emailCollection = a.Split(',');
如: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]);
}