Skip to content

Instantly share code, notes, and snippets.

@JamesSkemp
Created May 17, 2017 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JamesSkemp/5756f67df1dd4a609c77f5e60e013628 to your computer and use it in GitHub Desktop.
Save JamesSkemp/5756f67df1dd4a609c77f5e60e013628 to your computer and use it in GitHub Desktop.
LINQPad query to take a listing of emails, with some items containing comma-delimited list of emails, and finds distinct ones.

LINQPad query to take a listing of emails, with some items containing comma-delimited list of emails, and finds distinct ones.

var emails = new List<string>()
{
"test.one@example.com",
"test.one@example.com, test.two@example.com",
"test.two@example.com"
};

var cleanedEmails = new List<string>();

foreach (var email in emails)
{
	if (email.Contains(","))
	{
		cleanedEmails.AddRange(email.Split(','));
	}
	else
	{
		cleanedEmails.Add(email);
	}
}

cleanedEmails.Select(c => c.Trim()).Distinct().OrderBy(c => c).Dump();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment