-4

I have an example of an email address like this "mynameismine@hotmail.com", I just want to obtain or cut that string value and obtain this "mynameismine", I dont want to have "@hotmail.com".

Andres
  • 41
  • 2
  • 8

3 Answers3

5

If you're going to be manipulating email addresses you're best off using the MailAddress class in the System.Net.Mail namespace:

MailAddress addr = new MailAddress("mynameismine@hotmail.com");
string username = addr.User;
string domain = addr.Host;

username is the part before the '@' symbol and domain is the part after.

Calum
  • 1,809
  • 2
  • 19
  • 35
3
var newString = emailString.Split('@').First();

split the string up by @, grab the first item.

Jonesopolis
  • 24,241
  • 10
  • 66
  • 110
2

using System.Net.Mail;

MailAddress address = new MailAddress("mynameismine@hotmail.com");
string username = address.User;

Just a class specially for these purposes.

wingerse
  • 3,538
  • 1
  • 24
  • 54