-6

So i want to replace an normal email for example: "teste123@test.com" to "teste123 < b style ='display : none ;' > null < / b >@test.com"`

until now I've got this:

  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;

            }
  • Split on `@` and add your string or use https://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx and add your string. – Drag and Drop Jul 07 '17 at 09:02
  • What is the problem with this code? What is the expected output? Which email you want to replace in the code? – Chetan Jul 07 '17 at 09:03
  • You should NEVER have html code written as strings in C#. You're doing "styling of the UI" within code, and that's terrible separation of concern. Use CSS for that. You've also code half the code missing, there's a regex you're using there, and we can't see it :( – Dan Rayson Jul 07 '17 at 09:04
  • Like i sed i want the output to be from "teste123@test.com" to "teste123 < b style ='display : none ;' > null < / b >@test.com"` – dorin munteanu Jul 07 '17 at 09:05
  • If the Mail Template is more complex, you can still use [one](https://stackoverflow.com/a/10513059/6560478) of many Template processor. – Drag and Drop Jul 07 '17 at 09:17

1 Answers1

1
email = emails.Value.Replace("@","<b style='display:none;'>null</b>@");
Kemal Güler
  • 608
  • 1
  • 6
  • 21