udfIsStrPalindrome (sString)
;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfisstrpalindrome_1",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfisstrpalindrome_1

#DefineFunction udfIsStrPalindrome_1 (sString)
If sString=="" Then Return @FALSE
sString = StrClean(sString,"abcdefghijklmnopqrstuvwxyz0123456789","",@FALSE,2)
If sString=="" Then Return @FALSE
sString = StrLower(sString)
iStrLen = StrLen(sString)
iMid = iStrLen/2
iStrLen = iStrLen+1
For i=1 To iMid
   If StrSub(sString,i,1)!=StrSub(sString,iStrLen-i,1) Then Return @FALSE
Next
Return @TRUE
;..........................................................................................................................................
; This Function "udfIsPalindrome" returns a boolean value
; which indicates if a given string is a Palindrome or not.
; A Palindrome is a string which can be read either from left to right and from right to left.
; For Example: "madam".
;..........................................................................................................................................
#EndFunction

:skip_udfisstrpalindrome_1
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfisstrpalindrome_2",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfisstrpalindrome_2

#DefineFunction udfIsStrPalindrome_2 (sString)
If sString=="" Then Return @FALSE
sString = StrClean(sString,"abcdefghijklmnopqrstuvwxyz0123456789","",@FALSE,2)
If sString=="" Then Return @FALSE
iStrLen = StrLen(sString)
iMidL = iStrLen/2
iMidR = iStrLen-iMidL+1
sRev = ""
For ii=iStrLen To iMidR By -1
   sRev = StrCat(sRev,StrSub(sString,ii,1))
Next
Return !StriCmp(sRev,StrSub(sString,1,iMidL))
;..........................................................................................................................................
; This Function "udfIsPalindrome" returns a boolean value
; which indicates if a given string is a Palindrome or not.
; A Palindrome is a string which can be read either from left to right and from right to left.
; For Example: "madam".
;..........................................................................................................................................
#EndFunction

:skip_udfisstrpalindrome_2
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfisstrpalindrome_3",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfisstrpalindrome_3

#DefineFunction udfIsStrPalindrome_3 (sString)
If sString=="" Then Return @FALSE
sString = StrClean(sString,"abcdefghijklmnopqrstuvwxyz0123456789","",@FALSE,2)
If sString=="" Then Return @FALSE
iStrLen = StrLen(sString)
iMidL = iStrLen/2
iMidR = iStrLen-iMidL+1
sRev = ""
For ii=iMidR To iStrLen
   sRev = StrCat(StrSub(sString,ii,1),sRev)
Next
Return !StriCmp(StrSub(sString,1,iMidL),sRev)
;..........................................................................................................................................
; This Function "udfIsPalindrome" returns a boolean value
; which indicates if a given string is a Palindrome or not.
; A Palindrome is a string which can be read either from left to right and from right to left.
; For Example: "madam".
;..........................................................................................................................................
#EndFunction

:skip_udfisstrpalindrome_3
;------------------------------------------------------------------------------------------------------------------------------------------



:test1
; sTestStr = "REGEN"
; sTestStr = "EINNEGERMITGAZELLEZAGTIMREGENNIE"
; sTestStr = "RADAR"
; sTestStr = "CIVIC"
; sTestStr = "ABBA"
; sTestStr = "A man, a plan, a canal, Panama."
; sTestStr = "madam"
; sTestStr = "Lid off a daffodil"
; sTestStr = "Norma is as selfless as I am, Ron"

IsPalindrome1 = udfIsStrPalindrome_3("madam")
IsPalindrome2 = udfIsStrPalindrome_3("mad adam")



: Performancetest
sString = "Norma is as selfless as I am, Ron"
;sString = "RADAR"

iTest = 3

iLoop = 100

For it=1 To iTest

   Exclusive(@ON)
   iStart=GetTickCount()

   For ii=1 To iLoop
      vResult = udfIsStrPalindrome_%it%(sString)
   Next

   iStop=GetTickCount()
   Exclusive(@OFF)
   iTicks%it%=iStop-iStart

Next


:Result
iMax=0
For it=1 To iTest
   iMax = Max(iMax,iTicks%it%)
Next
For it=1 To iTest
   iPct%it% = 100*iTicks%it%/iMax
Next

sMsgTitle="Demo Performance Test  udfIsStrPalindrome (sString)"
sMsgText=""
For it=1 To iTest
   sMsgText = StrCat(sMsgText,"Test ",it,@TAB,iTicks%it%,@TAB,iPct%it%,"%%",@LF)
Next
Message(sMsgTitle,sMsgText)
ClipPut(sMsgText)
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
; in WinBatch Studio Debug Mode
;   Test 1 6766 100%
;   Test 2 6643 98%
;   Test 3 6696 98%
;------------------------------------------------------------------------------------------------------------------------------------------
; in WinBatch Studio Run Mode
;   Test 1 4945 100%
;   Test 2 4616 93%
;   Test 3 4279 86%  <== The Winner.
;------------------------------------------------------------------------------------------------------------------------------------------
;*EOF*