Function Palindrome, iterative Learn programming Visual Basic (VB.net)

Lesson:

Functions


Exercise:

Function Palindrome, iterative


Objetive:

Create an iterative function to say whether a string is symmetric (a palindrome). For example, "RADAR" is a palindrome.


Code:

Imports System
Public Class exercise130
    Public Shared Function IsPalindrome(ByVal text As String) As Boolean
        text = text.ToUpper()
        Dim begin As Integer = 0
        Dim [end] As Integer = text.Length - 1

        For begin = 0 To [end] - 1
            If text(begin) <> text([end]) Then Return False
            [end] -= 1
        Next

        Return True
    End Function

    Public Shared Sub Main()
        Console.WriteLine(IsPalindrome("radar"))
        Console.WriteLine(IsPalindrome("ratas"))
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.