[email protected];范幼敏,吴国民,王翔;[email protected];;;[email protected];变成:[email protected];[email protected];[email protected];
就是去掉多余分号,以及加逗号的人名.

解决方案 »

  1.   


    void Main()
    {
    string str="[email protected];范幼敏,吴国民,王翔;[email protected];;;[email protected];";
    str=Regex.Replace(str,@"(?:[\u4e00-\u9fa5]+[,;]|;{2,})",m=>Regex.IsMatch(m.Value,";{2,}")?";":"");
    Console.WriteLine(str);//[email protected];[email protected];[email protected];}
      

  2.   

    3楼的是一个办法,但是不能过滤掉诸如 123.com 这类字符,我猜测lz是要保留标准email地址格式的字符串,请使用下面这段代码:        public string Trans(string input)
            {
                //string input = "[email protected];范幼敏,吴国民,王翔;[email protected];;;[email protected];";
                string output = string.Empty;            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})");
                System.Text.RegularExpressions.MatchCollection mc = regex.Matches(input);            foreach (System.Text.RegularExpressions.Match m in mc)
                {
                    output += m.Value + ";";
                }            return output;
            }
      

  3.   

    我用: 
    string[] mc= System.Text.RegularExpressions.Regex.Split(MailTo, ";");
    MailTo="";
    for (int i = 0; i < mc.Length; i++)
                 {
    if(mc[i].ToString().Length>1&&mc[i].ToString().IndexOf(",")==-1){MailTo+=mc[i].ToString();MailTo+=";";}
                 }
      

  4.   


    你这个不行吧?
    你这个只能适合你提供的这个字符串,是个特例,不能包括所有的情况。
    比如   [email protected];范幼敏,吴国民,王翔;[email protected];;;[email protected];123;  最后这个123也是符合你的条件的。
    判断这些东西,不光要测试符合,还要测试不符合。
      

  5.   

    呼唤mafangming兄:请移步http://topic.csdn.net/u/20110616/19/ab5350f3-e8df-4b0a-a2fd-61876876eabc.html?11174