How to find missing alphabet characters from a string in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Module Module1

    Function GetMissingAlphabetChars(input As String) As List(Of Char)
        Dim present(25) As Boolean

        ' Normalize input: lowercase + keep only a..z
        For Each ch As Char In input.ToLower()
            If ch >= "a"c AndAlso ch <= "z"c Then
                present(Convert.ToInt32(ch) - Convert.ToInt32("a"c)) = True
            End If
        Next

        ' Collect missing letters
        Dim missing As New List(Of Char)
        For i As Integer = 0 To 25
            If Not present(i) Then
                missing.Add(Convert.ToChar(Convert.ToInt32("a"c) + i))
            End If
        Next

        Return missing
    End Function

    Sub Main()
        Dim missing = GetMissingAlphabetChars("VB.NET Programming")

        For Each ch As Char In missing
            Console.WriteLine(ch)
        Next
    End Sub

End Module


	
' run:
'
' c
' d
' f
' h
' j
' k
' l
' q
' s
' u
' w
' x
' y
' z
'

 



answered Mar 6 by avibootz
...