Results 1 to 5 of 5

Thread: Palidrome

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153
    I would like to check to see if a string of words reads the same when read backwards. Like the words "eye, eve", etc. Any ideas on this? thanks.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Dim strPalindrome As String
    Dim strStrip As String
    Dim intIndex As Integer

    strPalindrome = "A man a plan a canal Panama"

    For intIndex = 1 To Len(strPalindrome)
    If Mid$(strPalindrome, intIndex, 1) <> " " Then
    strStrip = strStrip & Mid$(strPalindrome, intIndex, 1)
    End If
    Next

    If UCase(strStrip) = StrReverse(UCase(strStrip)) Then
    MsgBox "It's a palindrome"
    End If

  3. #3
    Member
    Join Date
    Aug 2000
    Location
    Chennai , India
    Posts
    44
    This should work:
    Code:
    X = ""
    L = LEN(Text1.Text)
    FOR I = L TO 1 STEP -1
    X = X +  MID$(Text1.Text,I,1)
    NEXT I
    IF X = Text1.Text Then MsgBox "Palindrome"
    By the way,I think the word is Palindrome and not Palidrome.
    Rabin
    Windows : Visual Basic 6 Enterprise / 3.0 (16-bit)
    DOS : QBasic 4.5 , Visual Basic For DOS
    Web : HTML , VBScript , PHP (Learning)

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    rv2k's soultion won't work if there is more than one word and the words are different lengths (because of the spaces), but you can use his code to reverse the string instead of StrReverse if you don't have VB6.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 1999
    Posts
    153
    Thanks Martin! That works fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width