27 lines
730 B
Text
27 lines
730 B
Text
#APPTYPE CONSOLE
|
|
|
|
FUNCTION stripNonAlpha(BYVAL s AS STRING) AS STRING
|
|
DIM sTemp AS STRING = ""
|
|
DIM c AS STRING
|
|
FOR DIM i = 1 TO LEN(s)
|
|
c = MID(s, i, 1)
|
|
IF INSTR("ABCDEFGHIJKLMNOPQRSTUVWXYZ", c, 0, 1) THEN
|
|
sTemp = stemp & c
|
|
END IF
|
|
NEXT
|
|
RETURN sTemp
|
|
END FUNCTION
|
|
|
|
FUNCTION IsPalindrome(BYVAL s AS STRING) AS INTEGER
|
|
FOR DIM i = 1 TO STRLEN(s) \ 2 ' only check half of the string, as scanning from both ends
|
|
IF s{i} <> s{STRLEN - (i - 1)} THEN RETURN FALSE 'comparison is not case sensitive
|
|
NEXT
|
|
|
|
RETURN TRUE
|
|
END FUNCTION
|
|
|
|
PRINT IsPalindrome(stripNonAlpha("A Toyota"))
|
|
PRINT IsPalindrome(stripNonAlpha("Madam, I'm Adam"))
|
|
PRINT IsPalindrome(stripNonAlpha("the rain in Spain falls mainly on the rooftops"))
|
|
|
|
PAUSE
|