我有字符串,其中包含很多电子邮件ID。
我希望使用电子邮件格式从字符串中获取该电子邮件ID。 喜欢在@和Blankspace之后的空白空间@。
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."
然后我如何获得该电子邮件ID?
答案 0 :(得分:2)
您可以使用Split方法:
string email = "test@example.com"; string[] tokens = email.Split('@'); string enailId = tokens[0]; string domain = tokens[1];击>
<击> 撞击>
更新:
在您澄清之后,您将如何使用正则表达式解析电子邮件:
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);
}