2013-09-24 16 views

risposta

49

Usando MailAddress è possibile recuperare il Host da una proprietà invece

MailAddress address = new MailAddress("[email protected]"); 
string host = address.Host; // host contains yahoo.com 
2

O per soluzioni corda a base di:

string address = "[email protected]"; 
string host; 

// using Split 
host = address.Split('@')[1]; 

// using Split with maximum number of substrings (more explicit) 
host = address.Split(new char[] { '@' }, 2)[1]; 

// using Substring/IndexOf 
host = address.Substring(address.IndexOf('@') + 1); 
11

If Default's answer non è quello che si sta cercando può sempre Split l'e-mail stringa dopo il '@'

string s = "[email protected]"; 
string[] words = s.Split('@'); 

string[0] sarebbe xyz se si ha bisogno in futuro
string[1] sarebbe yahoo.com

Ma la risposta di default è certamente un modo più semplice di affrontare questo.

Problemi correlati