I read this question: Split List into Sublists with LINQ but it not help me for the following problem.
I have the following list
18
0
abcde
678
-----
23
1
abcde
-----
66
4
3rwer
1
another item
How can I split this list into sublist by -----
separator ?
Thanks
I'm not aware of an existing operator to do this in LINQ to Objects itself, more the MoreLINQ project has the Split
method, so you can use:
var sections = originalList.Split("-----");
That returns an IEnumerable<IEnumerable<string>>
- if you need a list of lists, you could use:
var sections = originalList.Split("-----")
.Select(section => section.ToList())
.ToList();
MoreLINQ has a NuGet package that you might wish to use for installation.
See more on this question at Stackoverflow