udfStrRotate
str udfStrRotate (str, int)
#DefineFunction udfStrRotate (strString, intByValue)
If intByValue == 0 Then Return strString
intLen = StrLen (strString)
intByValue = intByValue mod intLen
Return StrSub (strString : strString, 1 - intByValue + (intByValue > 0) * intLen, intLen)
; Detlev Dalitz.20090627.
#EndFunction


#DefineFunction udfStrRotate_ (strString, intByValue)
If intByValue == 0 Then Return strString
intLen = StrLen (strString)
intByValue = intByValue mod intLen
If intByValue > 0 Then Return StrSub (strString, 1 - intByValue + intLen, -1) : StrSub (strString, 1, intLen - intByValue)
Return StrSub (strString, 1 - intByValue, -1) : StrSub (strString, 1, -intByValue)
; Detlev Dalitz.20090627.
#EndFunction

; Test.

strTest = "123456789"
strString1 = udfStrRotate (strTest, 3)   ; "789123456" rotated right.
strString2 = udfStrRotate (strTest, 12)  ; "789123456" rotated right.
strString3 = udfStrRotate (strTest, -3)  ; "456789123" rotated left.
strString4 = udfStrRotate (strTest, -12) ; "456789123" rotated left.


strTest = "this is a string "
strString11 = udfStrRotate (strTest, 9)  ; "a string this is " rotated right.
strString12 = udfStrRotate (strTest, -8) ; "a string this is " rotated left.


BoxOpen ("Demo: udfStrRotateTest (strString, intByValue)", "")
strTest = "this is a string "
BoxText ("D|| " : strTest : " ||")
TimeDelay (1)
For intI = 1 To 29
   strTest = udfStrRotate (strTest, -2)
   TimeDelay (0.1)
   BoxText ("<< " : strTest : " <<")
Next
BoxText ("|| " : strTest : " ||")
TimeDelay (1)
For intI = 1 To 29
   strTest = udfStrRotate (strTest, 2)
   TimeDelay (0.1)
   BoxText (">> " : strTest : " >>")
Next
BoxText ("|| " : strTest : " ||")
TimeDelay (1)
BoxShut ()

Exit