How do I get the username and the domain from an email address of:
string email = "hello@example.com";
//Should parse into:
string username = "hello";
string domain = "example.com";
I’m seeking the shortest code to do this, not necessarily efficient.
Scenario: I want to parse it in my ASP.NET MVC view so I can cloak it.
Use the MailAddress class
This method has the benefit of also parsing situations like this (and others you may not be expecting):
In both cases above:
At the top of your file with the rest of your using directives add: