Download Quick Currency Converter


Ispalindrome, Palindrome test Visual Basic, VB.net

Description: A Palindrome is a string that reads the same backwards as forwards. For example, "madam" and "1331" are palindromes because if you reverse the spellings(or characters, if that matters), it is still the same word. This project checks if a given input string is a palindrome or not. Note that the project checks for a perfect palindrome , i.e , the spaces and punctuation marks are NOT ignored!

Difficulty: Easy

Language: VISUAL BASIC.NET (VB.NET)

Compiler/IDE: Visual Studio



View Source

            							
Module Module1

    Sub Main()

        Dim s As String
        Console.WriteLine("Enter a string to check if its palindrome")
        s = Console.ReadLine

        If check(s) Then
            Console.WriteLine("Yes, the string is a palindrome")
        Else
            Console.WriteLine("No, the string is not a palindrome")
        End If
        Console.ReadLine()

    End Sub

    Function check(ByVal s As String) As Boolean

        Dim len As Integer = s.Length
        For i As Integer = 0 To len / 2
            If Not s(i) = s(len - 1 - i) Then
                Return False
            End If
        Next

        Return True
    End Function

End Module

       


Notes:To check if an input string is palindrome or not, we compare first character with the last, second character with the second last and so on. When we reach at the middle of the string, we have made all the necessary comparisons and thus the loop exits at half the size of the input string. At any point, if the comparison returns false, we exit saying that the string is not a palindrome .