开发者

Get Email ID Format from string?

开发者 https://www.devze.com 2022-12-18 21:10 出处:网络
I have string where I have lot of email id in it. I开发者_如何学运维 want get that email id from string using email format.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消