I have a rather large list of strings that contains duplicates in the sense that if I only care if A,B,C are in a result, but not what order they are in. I looked for many other duplication removal solutions, but they typically only work for exact values(which I understand since these elements aren't exact dups, but more spurious or superfluous results.) I already have the list and didn't create it, so changing the selection is not an option.
            Asked
            
        
        
            Active
            
        
            Viewed 308 times
        
    4
            
            
        - 
                    1Are the results variable length? – nicholas Apr 25 '13 at 13:49
- 
                    possible duplicate: http://stackoverflow.com/questions/47752/remove-duplicates-from-a-listt-in-c-sharp?rq=1 – Danil Asotsky Apr 25 '13 at 13:49
- 
                    1Offtop: so frank and self-critic user name – sll Apr 25 '13 at 13:50
- 
                    4@DanilAsotsky, the OP is looking for removing duplicate permutations, not duplicate values. – nicholas Apr 25 '13 at 13:51
- 
                    they are the same length, but I would also like to know how to do variable length if anyone knows how to accomplish that. – StuckOnSimpleThings Apr 25 '13 at 13:52
- 
                    1@nicholas +1, but you *could* use `HashSet` if you sorted the string in the Hash function (http://msdn.microsoft.com/en-us/library/bb359100.aspx) – Chris Pfohl Apr 25 '13 at 13:53
1 Answers
10
            Simply sort the elements within each item first.
listOfStrings.Select(s => new string(s.OrderBy(c => c))).Distinct().ToList();
You see what I mean - sort the chars. I'll check the syntax of this momentarily..
 
    
    
        Kieren Johnstone
        
- 41,277
- 16
- 94
- 144
- 
                    ah, beat me to it. see what i was getting at with the same-length question? – nicholas Apr 25 '13 at 13:54
- 
                    
