Split a spread by list of indices

hi all,

I have a list.

000a
002a
002b
002c
005a
005b
011a
013a

I want to have one spread with sub spreads for each number.
I got the indices where to split the spread, but I can’t figure out how to split correctly.

Unbenannt

Also open for suggestions if there are new nodes which accomplish this much faster.

thx

Unbenannt

ok got it working.
still, maybe there is a new gamma way to do this?

GroupBy in the sequence category could be the one you’re looking for

1 Like

does not work with different spread counts, but good to know there are group nodes.

thx

demo that usecase? at least i don’t get it…

The group nodes either split the spread in a defined number or spreads, or in a variable number of spreads with a defined spreadcount. But they do not work for me because my subspreads all have different lengths.

There is also a region but I don’t know how to use it.


groupby.vl (19.5 KB)

not sure I understand your problem but does this help?

image

the GroupBy region allows you to tell how you want your stuff to be grouped. in this case we say we want to group based on the first three characters of the string. one might want to make something more sophisticated to make sure you’re dealing with numbers (yesyesregex) but this is just to demo the principle :)

then about the double foreach in the end… I don’t know really understand why we have to do it like that, but the splicer of the first foreach gives gives us a Grouping<T, T>, and the nodebrowser only allows us to access the Key, which is not what we want… so after having a look in MSDN there was this snippet :

foreach (var group in query)  
{  
    Console.WriteLine(group.Key == 0 ? "\nEven numbers:" : "\nOdd numbers:");  
    foreach (int i in group)  
        Console.WriteLine(i);  
}  

which translates to our nested foreach here, and allows us to access the elements of our groups.

edit well I guess since Grouping<T,T> is Enumerable then we are allowed to iterate over it with a foreach and access its elements, but yeah this is not really obvious :)

3 Likes

perfect!
exactly what I needed.
thx!

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.