I have a list of filenames that will look something like this:
So, in order to do this reliably, you'll need to manipulate the fact that you do, in fact, know that there's a pattern and reason to the various things. I'll assume the sort here is A-Z descending. Have some general algorithm:
Create a Dictionary<String, List<File>>. FOREACH File collect the first substring (0 to the first -) try to add the file to the dictionary using the substring as a key if it works, go to the next one Catch if the Key doesn't exist add the substring to the dictionary as a key with a new list add the file to the dictionary using the new key. end FOREACH FOREACH key in the dictionary sort the list alphabetically end FOREACH
So, dictionaries are really good at grouping things by a commonality, which you've made apparent is either the Switch key (SNc) or the name to the left of it (SAN3000A and the like). We can do this because also there is a common delimiter (-) for all the potential files, so I can reliably 'guess' where my key is coming from.