Linq Get Duplicate Count Of Words From String

Linq Get Duplicate Count Of Words From String

Linq Duplicate Words From String. Let’s see how to get duplicate words from string using Linq group by syntax. In upcoming chapter we will see Group by clause in more details. Linq Group by Multiple Columns example.

  1. Linq Chapter 1 – Split string to list of strings.
  2. Linq Chapter 2 – Remove duplicates from list.
  3. Linq Chapter 3 – Linq Where Clause.
  4. Linq Chapter 4 – Linq Group by multiple clause.
  5. Linq Chapter 5 – Linq Inner Join query.
  6. Linq Chapter 6 – Linq Distinct list.
  7. Linq Chapter 7 – Linq OfType Method. Linq count words.

void Main()
 var arrString = "Hello Satalaj, I'm calling you as a Satalaj. How are you Satalaj.".Split(" ".ToCharArray());
 var duplicates = from wordCollection in arrString
                  group wordCollection by wordCollection   into g
                  where g.Count() > 1
                  select new { g.Key, Count = g.Count() } ;                                           

Output shows found words.

Key Count
you 2
Satalaj. 2

Var duplicate is of IEnumerable type and holds the output of Linq expression.

We are grouping the words from string and filtering the result using where statement in Linq.

This example is quite difficult to understand for beginners. Believe me, once you learn Group by clause explained here with entity you will never forget it.


C# DateTime ToString()Linq Split String To ListLinq Group By Multiple ColumnsLinq Convert String Array To Int Convert String To String vs stringRegular expression for getting words from stringC# ArrayList Search using Linq Extension OfType MethodReplace string in C#DateTime format Time String[C#] Remove Last Character From String


My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.

I'm Satalaj.