Palindrome

This function checks whether the given string is palindrome or not.


Private Sub Palindrome()
Dim strChar As String
Dim intI, intJ As Integer
Dim strAry(10) As String

strChar = "madam"
ReDim strAry(strChar.Length - 1)
For intI = 1 To strChar.Length
strAry(intI - 1) = Mid$(strChar, intI, 1)
Next

intJ = strAry.Length - 1
For intI = 0 To strAry.Length - 1
If intI > intJ Then
MessageBox.Show("Palindrome")
Exit Sub
End If
If strAry(intI) = strAry(intJ) Then
intJ = intJ - 1
Else
Exit For
End If
Next
MessageBox.Show("Not Palindrome")
End Sub

In the above code,I have passed the string "madam" which is a palindrome.You may change it as per your requirement.


Comments

No responses found. Be the first to comment...