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

51,857 answers

573 users

How to find longest palindrome substring in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
    Public Shared Function longestPalindromeSubstring(ByVal str As String) As Integer
        Dim len As Integer = str.Length
        Dim longestLength As Integer = 1, start As Integer = 0

        For i As Integer = 0 To len - 1
            For j As Integer = i To len - 1
                Dim palindrome As Integer = 1

				For k As Integer = 0 To (j - i + 1) / 2 - 1
                    If str(i + k) <> str(j - k) Then
                        palindrome = 0
                    End If
                Next

                If palindrome <> 0 AndAlso (j - i + 1) > longestLength Then
                    start = i
                    longestLength = j - i + 1
                End If
            Next
        Next

        Console.Write("Longest palindrome substring = ")

        For i As Integer = start To start + longestLength - 1
            Console.Write(str(i))
        Next

		Console.WriteLine()
        Return longestLength
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim str As String = "qabcbaproggorpxyyxzv"

        Dim result As Integer = longestPalindromeSubstring(str)

        Console.Write("Length palindrome substring length = " & result)
    End Sub
End Class





' run:
'
' Longest palindrome substring = proggorp
' Length palindrome substring length = 8
'

 



answered Jun 3, 2023 by avibootz
...