How to find missing alphabet characters from a string in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;

class Program
{
    static List<char> GetMissingAlphabetChars(string input) {
        bool[] present = new bool[26];

        // Normalize input: lowercase + keep only a..z
        foreach (char c in input) {
            char lower = char.ToLower(c);
            if (lower >= 'a' && lower <= 'z') {
                present[lower - 'a'] = true;
            }
        }

        // Collect missing letters
        var missing = new List<char>();
        for (int i = 0; i < 26; i++) {
            if (!present[i]) {
                missing.Add((char)('a' + i));
            }
        }

        return missing;
    }

    static void Main()
    {
        var missing = GetMissingAlphabetChars("C# Programming");

        foreach (char c in missing) {
            Console.WriteLine(c);
        }
    }
}



/*
run:

b
d
e
f
h
j
k
l
q
s
t
u
v
w
x
y
z

*/

 



answered Mar 6 by avibootz
...