[Solved] c# finding different words in two texts [closed]


string text1 = "hello, world apple,pineapple,cabbage,apple";
string text2 = "hello, world,pineapple";

string pattern = @"\p{L}+";

var list1 = Regex.Matches(text1, pattern).Cast<Match>().Select(x => x.Value);
var list2 = Regex.Matches(text2, pattern).Cast<Match>().Select(x => x.Value);


var result =   list1.Where(x => !list2.Contains(x))
                .GroupBy(x => x)
                .Select(x =>new
                {
                    Word = x.Key,
                    Count= x.Count()
                })
                .ToList();

This will return

Word = apple,   Count = 2
Word = cabbage, Count = 1

Of course there is room for some performance improvements but it’ll leave them out for clarity…

solved c# finding different words in two texts [closed]