CHECKING PALINDROMES

array palindromes

Page 1 of 1

2 Replies - 33414 Views - Last Post: 10 April 2007 - 07:45 AM Rate Topic: -----

#1 sidyey   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 15-November 06

CHECKING PALINDROMES

Post icon  Posted 15 November 2006 - 10:07 AM

the code that i only know is..

Private Sub Command1_Click()
Dim st As String, rst As String
st = InputBox("Enter any string")
st = UCase(st)

For i = Len(st) To 1 Step -1
rst = rst & Mid(st, i, 1)
Next i

If rst = st Then
Console.write "Palindrome"
Else
Console.Write "Not-Palindrome"
End If
End Sub


_______________________________________
i really dont know how to construct array..
please help me with this..

i dont have any installer of VB .NET right now..
i only do some of my projects and homeworks in school.

could somebody help me with this?
i want to display the palindrome or not palindrome in a messagebox..

ang using text input box, how will i be able to accpt inputs or phrase using it?

HERES THE BROBLEM:


a program to accept a string and [b]determines
if the String is a palindrome
. Define a recursive procedure
TestPalindrome that returns True if the String stored in the
array is a palindrome, but False otherwise.

The procedure should ignore spaces and punctuation in the String. [Hint: A String can be converted to a Char array using method ToCharArray. For instance, the statement:

myArray = myString.ToCharArray()

stores the contents of string variable myString in
one-dimensional Char array myArray.]

This post has been edited by sidyey: 15 November 2006 - 10:19 AM


Is This A Good Question/Topic? 0
  • +

Replies To: CHECKING PALINDROMES

#2 LemonMan   User is offline

  • D.I.C Head
  • member icon

Reputation: 15
  • View blog
  • Posts: 170
  • Joined: 22-August 05

Re: CHECKING PALINDROMES

Posted 01 April 2007 - 04:54 PM

I see this problem all the time!!! just use this code:

If LCase(MyString) = LCase(StrReverse(MyString)) Then
'It is a palindrome
Else
'It is not a palindrome
End If



MyString is the string to check if it is a palindrome or not.

hope it helps
Was This Post Helpful? 0
  • +
  • -

#3 astralvoid   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 10-April 07

Re: CHECKING PALINDROMES

Posted 10 April 2007 - 07:45 AM

View Postsidyey, on 15 Nov, 2006 - 10:07 AM, said:

the code that i only know is..

Private Sub Command1_Click()
Dim st As String, rst As String
st = InputBox("Enter any string")
st = UCase(st)

For i = Len(st) To 1 Step -1
rst = rst & Mid(st, i, 1)
Next i

If rst = st Then
Console.write "Palindrome"
Else
Console.Write "Not-Palindrome"
End If
End Sub


_______________________________________
i really dont know how to construct array..
please help me with this..

i dont have any installer of VB .NET right now..
i only do some of my projects and homeworks in school.

could somebody help me with this?
i want to display the palindrome or not palindrome in a messagebox..

ang using text input box, how will i be able to accpt inputs or phrase using it?

HERES THE BROBLEM:


a program to accept a string and determines
if the String is a palindrome
. Define a recursive procedure
TestPalindrome that returns True if the String stored in the
array is a palindrome, but False otherwise.

The procedure should ignore spaces and punctuation in the String. [Hint: A String can be converted to a Char array using method ToCharArray. For instance, the statement:

myArray = myString.ToCharArray()

stores the contents of string variable myString in
one-dimensional Char array myArray.]



Your problem tells you to create a [b]recursive function
to figure this out. Just make a new recursive function that:

sets a 'break point' to escape the recursion such as when characters left = 1 or 0,
then recursively check the first character in the array with the last character until either 1 or 0 characters are left in the array.

eg.

Check if length of end - beginning == 1 or less characters, then return true.

if first character in array == last character in array then it's still a palindrome
{
so, increase the beginning index + 1 and decreasing the ending index -1
Call the same function again with new indexes.
}
else
{
It's not a palindrome, so return false
}







hope this helps!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1