Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split each two-word string in a list, compare if same and count using Linq

Tags:

c#

linq

Is it possible to split each string (containing 2 words) in a list, then compare if both words are the same and count that occurrences using Linq? For example:

Let's say I have a list containing

list[0] = "bla bla";
list[1] = "bla heh";
list[2] = "heh heh";

The output of count should be 2 in this case.

my attempt so far:

var count = lst.Count(c => c.Split(.......)....

can't get past this.

Any help would be greatly appreciated.

like image 581
no use for a name Avatar asked Jan 28 '23 07:01

no use for a name


1 Answers

list.Select(c => c.Split(' ')).Count(y => y.Length >= 2 && y[0] == y[1]);
like image 158
Adeoluwa Simeon Avatar answered Feb 06 '23 11:02

Adeoluwa Simeon