I have a code like
string code = \"AABBDDCCRRFF\";
In this code, I want to retrieve only distinct characters
The Output should be l
string code = "AABBDDCCRRFF";
string answer = new String(code.Distinct().ToArray());
How about in linq:
var str = "AABBCCDDDDDDEEEEEFFF";
var unique = str.ToCharArray().Distinct();
Console.WriteLine("Answer: {0}.", string.Join(string.Empty, unique));
You can do this as follows
var s = "AABBDDCCRRFF";
var result = s.Distinct();
var distinct = result.Aggregate(string.Empty, (current, c) => current + c.ToString());
Console.WriteLine(distinct);