How to find the longest repeating character in a string with VB.NET

1 Answer

0 votes
Imports System
Imports System.Linq

Public Class Program
	Public Shared Sub Main()
        Dim str As String = "aabbbbhhhhhhhdddefgggg88"
		
        Dim longest_repeating_character As String = New String(str.Select(Function(ch, index) str.Substring(index).TakeWhile(Function(e) e = ch)).OrderByDescending(Function(e) e.Count()).First().ToArray())
        
		Console.WriteLine(longest_repeating_character)
    End Sub
End Class





' run:
'
' hhhhhhh
' 

 



answered Sep 1, 2023 by avibootz

Related questions

...