Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,926 questions

51,859 answers

573 users

How to count occurrences of each letter in a char array with VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class CountLettersInCharArray
	Public Shared Sub Main()
        Dim charArray As Char() = {"V"c, "B"c, "p"c, "r"c, "o"c, "g"c, "r"c, "a"c, "m"c, "m"c, "i"c, "n"c, "g"c}
        Dim letterCount As Dictionary(Of Char, Integer) = New Dictionary(Of Char, Integer)()

        For Each c As Char In charArray
            If letterCount.ContainsKey(c) Then
                letterCount(c) += 1
            Else
                letterCount(c) = 1
            End If
        Next

        For Each item In letterCount
            Console.WriteLine($"Letter {item.Key}: {item.Value} times")
        Next
    End Sub
End Class



' run:
'
' Letter V: 1 times
' Letter B: 1 times
' Letter p: 1 times
' Letter r: 2 times
' Letter o: 1 times
' Letter g: 2 times
' Letter a: 1 times
' Letter m: 2 times
' Letter i: 1 times
' Letter n: 1 times
'  

 



answered Mar 2, 2025 by avibootz
...