Hey guys,
I'm new to revolution and have to figure out a program to have the user input a phrase or series of numbers and check to see if what they entered is a palindrome. Unfortunately, I don't know how to do it on Revolution.
Normally I would find the length of the string, then match up the first letter with the last letter, 2nd with the 2nd to last, etc.
Also, it seemed like there was a "reversed" code. I tried to do it but it didn't work. I also have to consider blank spaces that users may enter in the phrase.
If someone could give me a concrete code or talk me through how to do this with Revolution code, I would greatly appreciate it.
Reversing a string
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- VIP Livecode Opensource Backer
- Posts: 977
- Joined: Sat Apr 08, 2006 7:47 am
- Contact:
To reverse a string, use the foillowing function.
But that might be a little overkill.
Hope this helped,
Jan Schenkel.
Code: Select all
function ReversedString pString
local tIndex, tReversedString
repeat with tIndex = the length of pString down to 1
put char tIndex of pString after tReversedString
end repeat
return tReversedString
end ReversedString
Code: Select all
function IsAPalindrome pString
local tLength, tIndex
put the length of pString into tLength
repeat with tIndex = 1 to tLength DIV 2
if char tIndex of pString is not char (tLength - tIndex + 1) of pString
then return false
end repeat
return true
end IsAPalindrome
Jan Schenkel.
Quartam Reports & PDF Library for LiveCode
www.quartam.com
www.quartam.com