Monday, March 14, 2011

VBScript code to check if a string is Palindrome or not

'Program to check if the given string is a Palindrome or not

MyStr=Ucase(inputbox("Enter the String:"))
RevStr=strreverse(MyStr)

if strcomp(MyStr,RevStr)=0 then
   msgbox "It is a Palindrome"
else
   msgbox "It is not a Palindrome"
end if

More VB Scripts here.

13 comments:

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. pls send me a vbscript program that containes a textbox to accept a string and a button.when user clicks the button the script checks whether the string is palindrome or not

    ReplyDelete
  3. above related query with out using reverse string function

    ReplyDelete
  4. same as above query with out using reverse string function how to write logic please help me

    ReplyDelete
    Replies
    1. Dim str1, rstr1,nCnt1, i
      str1= inputbox("Enter a string")
      rstr1=""
      'reversing the string
      For i=len(str1) to 1 step -1
      rstr1=rstr1&mid(str1,i,1)
      Next
      msgbox("the reverse of the entered string is:"&rstr1)
      'comparing the string to check if it is palindrome
      If strcomp(str1,rstr1) Then
      msgbox("the entered string is palindrome")
      End If

      Delete
  5. how to write a palindrome program without using string function in VB script?

    ReplyDelete
  6. str = "xyzyssda"
    strReverse = ""

    For n = len(str) to 1 Step - 1
    strReverse = strReverse&Mid(str,n,1)

    Next
    Msgbox Trim(strReverse)
    'Try this code out

    ReplyDelete
    Replies
    1. this script is not working and showing the error from the strReverse step.

      Delete
  7. just adding of above prog
    dim a,b
    str = inputbox("enter the string:")

    For n = len(str) to 1 step- 1
    b=Mid(str,n,1)
    a = a+b

    Next
    Msgbox ("the string is"&a)
    if str=a then
    msgbox "this is a palandrome"
    else
    msgbox "it's not a palandrome"
    end if

    ReplyDelete
  8. please tel me whether third party tool can be accessed using the script

    ReplyDelete
  9. Did any one pls advice me how to print a palindrome string using for loop and if condition?

    ReplyDelete
  10. Dim str1, rstr1,nCnt1, i
    str1= inputbox("Enter a string")
    rstr1=""
    'reversing the string
    For i=len(str1) to 1 step -1
    rstr1=rstr1&mid(str1,i,1)
    Next
    msgbox("the reverse of the entered string is:"&rstr1)
    'comparing the string to check if it is palindrome
    If strcomp(str1,rstr1)=0 Then
    msgbox("the entered string is palindrome")

    else
    msgbox("the entered string is not palindrome")
    End If

    ReplyDelete
  11. " Hi This will work perfectly for Whether string is Polindrome or not
    Dim str1, rstr1,nCnt1, i
    str1= inputbox("Enter a string")
    rstr1=""
    'reversing the string
    For i=len(str1) to 1 step -1
    rstr1=rstr1&mid(str1,i,1)
    Next
    msgbox("the reverse of the entered string is:"&rstr1)
    'comparing the string to check if it is palindrome
    If strcomp(str1,rstr1)=0 Then
    msgbox("the entered string is palindrome")

    else
    msgbox("the entered string is not palindrome")
    End If

    ReplyDelete

Please leave your comment here...