---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
-- PALINDROME CHECK
--
-- Use a repeat loop to check if the characters (or numbers) in the first half of a
-- field are equal to the characters in the last half, starting from the last one.
--
-- Kurt * Belgium 05/14/2001
--
---------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------
on mouseup me
--First this behavior counts how many characters there are in your word,
--and puts this number in a variabele.
Characters = (member "Word").chars.count
--The number of characters is divided in two (integer division), so the repeat
--loop can compare the characters in the first half with the characters in the last half
Firsthalf = Characters / 2
--The value in Palindrome is used later, when its equal to the value in Firsthalf;
--the word is a palindrome.
Palindrome = 0
repeat with I = 1 to Firsthalf
--If the first character = the last character Palindrome's value gets increased
if (member "Word").char[I] = (member "Word").char[Characters] then
Palindrome = Palindrome + 1
end if
--The last character becomes the last but one ("I" will represent the second
--character in the next loop)
Characters = Characters - 1
end repeat
--If the two values match, it's a palindrome,it doesn't matter if the word has
--an odd number of characters, the one in the middle isn't compared to anything.
if Palindrome = Firsthalf then
alert "This is a palindrome !"
else
alert "This is not a palindrome !"
end if
end mouseup
Contact
MMI
36 South Court Sq
Suite 300
Newnan, GA 30263
USA