How to categorize elements of an array

Hi, I’m trying to categorize the elements of an array.

For example, I have an array of string:
{ReportAA1231, ReportBB2001, ReportCC2879, ReportBB9918, ReportAA8612, ReportBB1111}
And those elements that have same first 8 characters need to be put together. (ex. “ReportAA”, “ReportBB”, “ReportCC”)

The result can be in a 2-dimendinal array or list like below:
{{ReportAA1231, ReportAA8612},
{ReportBB2001, ReportBB9918, ReportBB1111},

Is there anyway to do this? Thanks!


How about the following?

arrStr.GroupBy(Function(s) s.Substring(0,8)).ToDictionary(Function(g) g.Key,Function(g) g.ToArray)

This expression returns dictionary. I think it’s better than array in this case.

Main.xaml (6.8 KB)


1 Like

Thank u!

1 Like

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