How to print histogram of frequencies of characters in string with VB.NET

1 Answer

0 votes
Imports System

Public Class Program
	Public Shared Sub Main()
        Dim lettercount As Integer() = New Integer(255) {}
        Dim s As String = "VB.NET, is a multi-paradigm, object-oriented programming language"

        For i As Integer = 0 To s.Length - 1
			lettercount(Convert.ToInt32(s(i))) += 1
        Next

        For i As Integer = 0 To 256 - 1
            If lettercount(i) <> 0 Then
                Dim stars As String = ""

                For j As Integer = 0 To lettercount(i) - 1
                    stars += "*"
                Next

                Console.WriteLine(Convert.ToChar(i) & " " & stars)
            End If
        Next
    End Sub
End Class




' run:
'
'   ******
' , **
' - **
' . *
' B *
' E *
' N *
' T *
' V *
' a ******
' b *
' c *
' d **
' e ****
' g *****
' i *****
' j *
' l **
' m ****
' n ***
' o ***
' p **
' r ****
' s *
' t ***
' u **
' 

 



answered Oct 4, 2021 by avibootz
...