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,774 questions

51,679 answers

573 users

How to find highest frequency character in a string with VB.NET

1 Answer

0 votes
Imports System
				
Public Module Module1
	Dim TOTLAASCII As Integer = 256
       
	Function get_highest_frequency_character(s As String) As Char 
		Dim arr(TOTLAASCII) As Integer
 
		Dim len As Integer = s.Length
		For i As Integer = 0 To len - 1
            arr(Convert.ToInt32(s(i))) += 1
		Next
       
		Dim max As Integer = arr(0) 
        Dim ch As Char = " " 
		For i As Integer = 0 To len - 1
			If max < arr(Convert.ToInt32(s(i))) Then
                max = arr(Convert.ToInt32(s(i)))
                ch = Convert.ToChar(s(i)) 
			End If 
       	Next
       
        return ch
	End Function			
	Public Sub Main()
		Dim s As String = "javac++phpcpythonc#"
         
        Console.Write("Highest frequency character: {0}", get_highest_frequency_character(s))
	End Sub
End Module



' run:
'
' Highest frequency character: c
'

 



answered Jan 20, 2021 by avibootz

Related questions

1 answer 176 views
1 answer 150 views
1 answer 115 views
2 answers 223 views
...