1

Output unique symbols ignoring case

IDictionary<char, int> charDict = new Dictionary<char, int>();

foreach (var ch in text)
{
    if (!charDict.TryGetValue(ch, out n)) {
        charDict.Add(new KeyValuePair<char, int>(ch, 1));
    } else
    {
        charDict[ch]++;
    }
}

Appellodppsafs => Apelodsf

And Is it possible not to use LINQ?

2 Answers2

1

Use a HashSet<char> to remember existing characters (that's what Distinct() does internally)

Assuming your input and expected result are type string

string input = "Appellodppsafs";
HashSet<char> crs = new HashSet<char>();
string result = string.Concat(input.Where(x => crs.Add(char.ToLower(x)))); //Apelodsf
fubo
  • 44,811
  • 17
  • 103
  • 137
0

You can try this (if you do not have long strings or performance issues):

string str = "Appellodppsafs";

string result = string.Concat(str.Select(s => $"{s}")
                               .Distinct(StringComparer.InvariantCultureIgnoreCase));

Console.WriteLine(result);

Output:

Apelodsf

SᴇM
  • 7,024
  • 3
  • 24
  • 41
  • In case of `Distinct()` you can't guarentee the right order of the characters https://stackoverflow.com/questions/4734852/does-c-sharp-distinct-method-keep-original-ordering-of-sequence-intact – fubo Oct 31 '18 at 12:36
  • Well, the correctness depends how OP will use the result. – SᴇM Oct 31 '18 at 12:48