Answer the question
In order to leave comments, you need to log in
How to remove duplicate words (and phrases) in a comma separated string?
There is some original line:
енот, енот, гваделупский енот, косумельский енот, енот, енот-полоскун, енот-ракоед, косумельский енот
енот
is repeated 3 times, and I need to remove 2 of these 3 words, leaving only the first word енот
. косумельский енот
is repeated 2 times, and you need to delete one of these phrases. енот, гваделупский енот, косумельский енот, енот-полоскун, енот-ракоед
Answer the question
In order to leave comments, you need to log in
ideone.com/4z7HsT
using System;
using System.Collections.Generic;
using System.Linq;
public class Test
{
public static void Main()
{
string text = "енот, енот, гваделупский енот, косумельский енот, енот, енот-полоскун, енот-ракоед, косумельский енот";
var result = text.Split(',').Select(x => x.Trim()).Distinct().Aggregate((r, word) => r + ", " + word);
Console.WriteLine(result);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question