Reputation: 2037
I have a string array of 3000 words. How can I divide the array into groups of ten using LINQ. Each ten items should be stored in one variable. The result should be a new array containing the groups.
Upvotes: 2
Views: 150
Reputation: 726609
Assuming that the words are separated by single space, you can split and re-group like this:
var res = longWord
.Split(' ').
.Select((s, i) => new { Str = s, Index = i })
.GroupBy(p => p.Index / 10)
.Select(g => string.Join(" ", g.Select(v => v.Str)));
Upvotes: 1