C# 替换电子邮件字符串
因此,我想替换普通电子邮件,例如:C# 替换电子邮件字符串,c#,asp.net-mvc,model-view-controller,C#,Asp.net Mvc,Model View Controller,因此,我想替换普通电子邮件,例如:“teste123@test.com“到 “teste123null@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
“teste123@test.com“
到
“teste123null@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;
}
字符串表达式=@(([^()\[\]\\,;:\s@']+(\.[^()\[\]\,;:\s@']+)*('.+')@(\[[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.+];
正则表达式rx=新正则表达式(表达式);
MatchCollection matches=rx.matches(conteudo.PaginaConteudo);
WriteLine(“{0}个匹配项位于:\n{1}”,
匹配,计数,
帕吉纳孔杜多);
字符串电子邮件,
replacement=“null”,
梅伦克,
修正字符串;
foreach(匹配中的匹配电子邮件)
{
email=email.Value;
mailenc=“”+电子邮件+替换+”;
correctString=conteudoooriginal.PaginaConteudo.Replace(email,mailenc);
conteudoooriginal.PaginaConteudo=正确字符串;
}
email=email.Value.Replace(@”,“null@”);
在@
上拆分并添加字符串,或者使用并添加字符串。此代码有什么问题?预期产量是多少?您希望在代码中替换哪封电子邮件?您不应该让html代码在C#中以字符串形式编写。您正在代码中进行“UI样式化”,这是一种可怕的关注分离。使用CSS实现这一点。您还编写了一半缺少的代码,您正在使用一个正则表达式,但我们看不到它:(就像我sed一样,我希望输出来自“teste123@test.com至“teste123null@test.com”如果邮件模板更复杂,您仍然可以使用许多模板处理器。@多林蒙特努,如果它工作,然后考虑。我可以有您的Skype,所以我可以问更多关于这个话题的问题吗?@ Kealg ULLeRes是我的Skype ID:Kimgalulr @ DelunMuntAu
email = emails.Value.Replace("@","<b style='display:none;'>null</b>@");