Link to home
Start Free TrialLog in
Avatar of JElster
JElsterFlag for United States of America

asked on

C# - How to remove duplicates from a string

Hi..
I have a string of email addreses with duplicates like this.
How can I remove the dups.. maybe use Split and LINQ?

"jon@abc.com; mary@xyz.com ; jon@ABC.com;  MARY@xyZ.com"

I want to return
"jon@abc.com; mary@xyz.com"

thx
ASKER CERTIFIED SOLUTION
Avatar of Snarf0001
Snarf0001
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You have to convert to lowercase as per my example, otherwise it's not going to trim out the case differences.
Yes, in my code just add a ".ToLower" right inbetween "yourEmailList" and "Split".  Thanks Snarf.
string[] emails = yourEmailList.ToLower.Split(';');

Open in new window