Lets assume we have the following array
var arr = new string[] {"foo","bar","jar","\r","a","b,"c","\r","x","y","z","\r");
Also ignore the fact that this is strings, so no string hack solutions please.
I want to group these elements by each “\r” in the sequence.
That is, I want one array/enumerable with “foo”,”bar”,”jar” and another with “a”,”b”,”c” etc.
Is there anything in the ienumerable extensions that will let me do this or will I have to roll my own group by method here?
I wrote an extension method for this purpose which works on any
IEnumerable<T>.For example, in your case, you can use it like this:
This will print:
(including a blank line at the end, because there is a
"\r"at the end of your collection).