How to find whether the string is palindrome or not?
To find whether the input string is palindrome or not.
MyStr= "ASA"
RevStr=strreverse(MyStr)
If MyStr = RevStr then
msgbox "It is a Palindrome"
Else
msgbox "It is not a Palindrome"
End if
(OR)
MyStr=”QTP”
RevStr=strreverse(MyStr)
If strcomp(MyStr,RevStr)=0 then
msgbox "It is a Palindrome"
Else
msgbox "It is not a Palindrome"
End if
(or)
Palindrome without built-in function:
Word="level"
lengthVar = Len(Word)
For i = 1 To lengthVar
v1 = v1 + Mid(Word, i, 1)
Next
For i = lengthVar To 1 Step -1
v2 = v2 + Mid(Word, i, 1)
Next
If v1 = v2 Then
MsgBox "given word is palindrome"
Else
MsgBox "given word is not palindrome "
End If
MyStr= "ASA"
RevStr=strreverse(MyStr)
If MyStr = RevStr then
msgbox "It is a Palindrome"
Else
msgbox "It is not a Palindrome"
End if
(OR)
MyStr=”QTP”
RevStr=strreverse(MyStr)
If strcomp(MyStr,RevStr)=0 then
msgbox "It is a Palindrome"
Else
msgbox "It is not a Palindrome"
End if
(or)
Palindrome without built-in function:
Word="level"
lengthVar = Len(Word)
For i = 1 To lengthVar
v1 = v1 + Mid(Word, i, 1)
Next
For i = lengthVar To 1 Step -1
v2 = v2 + Mid(Word, i, 1)
Next
If v1 = v2 Then
MsgBox "given word is palindrome"
Else
MsgBox "given word is not palindrome "
End If



Comments
Post a Comment