替换邮件字符串

时间:2017-07-07 08:59:28

标签: c# asp.net-mvc model-view-controller

所以我想替换正常的电子邮件,例如:"teste123@test.com"  “teste123< b style ='display:none;' > null< / b> @ test.com“`

直到现在我才知道了:

  string expression = @"(([^<>()\[\]\\.,;:\s@']+(\.[^<>()\[\]\\.,;:\s@']+)*)|('.+'))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))";
            Regex rx = new Regex(expression);
            MatchCollection matches = rx.Matches(conteudo.PaginaConteudo);
            Console.WriteLine("{0} matches found in:\n   {1}",
                     matches.Count,
                     conteudo.PaginaConteudo);

            string email,
                   replacement = "<h5 style='display:none;'>null</h5>",
                   mailenc,
                   correctString;

            foreach (Match emails in matches)
            {
                email = emails.Value;
                mailenc = "<h5>"+email + replacement+"</h5>";
                correctString = conteudoOriginal.PaginaConteudo.Replace(email, mailenc);
                conteudoOriginal.PaginaConteudo = correctString;

            }

1 个答案:

答案 0 :(得分:1)

email = emails.Value.Replace("@","<b style='display:none;'>null</b>@");