If I have a long-ish string of text and wanted to pull out words which are greater than 4 characters in length and found more than 4 times in the string, can LINQ do that?
You may be able to tighten this up, but I believe it will be something to the effect of
var results = inputstring.Split()
.Where(word => word.Length > 4)
.GroupBy(word => word)
.Where(grp => grp.Count() > 4)
.Select(grp => grp.Key);
You will, of course, need to decide how you wish to deal with any punctuation that might be present.
So given the input
var inputstring = @"The quick brown fox jumped over the lazy dog
The quick brown fox jumped over the lazy dog
The quick fox jumped over the lazy dog
The quick fox jumped over the lazy dog
The quick brown fox jumped over the lazy dog";
The results contain "quick" and "jumped" because the only other word greater than 4 characters ("brown") appeared just 3 times.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With