Get Email ID Format from string?
I have string where I have lot of email id in it.
I开发者_如何学运维 want get that email id from string using email format. like blankspace before @ and Blankspace After @.
suppose i have string like this then how can i do this?
"Yunnan Coffee with the scientific name-Coffee test@example.com Arabica L was the variation of Arabia Coffee."
Then How can i get that Email id?
You could use the Split method:
string email = "test@example.com"; string[] tokens = email.Split('@'); string enailId = tokens[0]; string domain = tokens[1];
UPDATE:
After your clarification here's how you could parse the email using a regular expression:
var regex = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*", RegexOptions.Compiled);
var s = "Yunnan Coffee with the scientific name-Coffee test@example.com Arabica L was the variation of Arabia Coffee.";
foreach (Match email in regex.Matches(s))
{
Console.WriteLine(email.Value);
}
精彩评论