I’m trying to get a distinct list of characters (case sensitive) across all strings in a list.
I have a list containing 3 strings:
"AABbDDCCRRFF"
"JOJaCK"
"BILLY"
The Output should be like (order of the characters is not important):
ABDCRFJOKaILYb
I know the below is wrong but can’t work it out:
distChars = (from string row in valuesList[c]
select row.Distinct()
).Distinct().ToString();
Does anyone know how to return the distinct characters from across each string. If this can’t be done in LINQ then i’m open to alternatives.
Thanks!
Update:
wow, great answers, so fast! What would be the approach to get the characters ordered alphabetically or by frequency of occurence?
In your code, you’re first selecting the distinct characters from within each row, then selecting the distinct sequences of characters, and finally calling
ToStringon anIEnumerable<T>.I would suggest that you first select all characters from all your rows, apply the
Distinctfilter on the combined sequence, and finally callstring.Concatto concatenate the resultant sequence of characters: