例如,我有一个电子邮件列表,例如:
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f899b89c9795999196d69b9795" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c7e5c7873717d7572327f7371" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d0b390b4bfbdb1b9befeb3bfbd" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="f094b0838592de949f9d91999ec2de939f9d" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3c5b7c4f495e125853515d55520e125f5351" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="166e56717b777f7a3875797b" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="532a13323d323f2a273a30207d343e323a3f7d303c3e" rel="noreferrer noopener nofollow">[email protected]</a>
<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d2a892abb3babdbdfcb1bdbf" rel="noreferrer noopener nofollow">[email protected]</a>
我想获取@
之后的部分,并且只获取一次(唯一)。
到目前为止我已经尝试过:
string[] campusCup(string[] emails)
{
var hs = new HashSet<string>();
var emailList = emails.Select(x => new { domain = x.Split('@')[1] })
.Where(x => hs.Add(x.domain) && Write(x.domain));
return hs.ToArray();
}
当我尝试调试它时,我的解决方案似乎没有选择任何内容。
最佳答案
试试这个:
var domains = emails.Select(email => email.Split('@')[1]).Distinct().ToList();
关于c# - 从电子邮件列表中获取唯一域的列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51102298/