udfStrOverlay
str udfStrOverlay (str, str, int, int, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrOverlay (strNew, strTarget, intStart, intLength, strPadChar)
If !StrLen (strNew) Then Return strTarget
intTargetLength = StrLen (strTarget)
If !intTargetLength Then Return ""
If strPadChar == "" Then sPadChar = " "
intLength = Max (0, intLength)
intStart = Max (0, intStart)
Return StrSub (StrCat (StrSub (strTarget, 1, intStart - 1), StrFix (strNew, strPadChar, intLength), StrSub (strTarget, intStart + intLength, -1)), 1, intTargetLength)
;..........................................................................................................................................
; Returns string strTarget with the string strNew overlayed at position intStart.
; Prior to the operation, strNew is truncated to intLength
; or padded to intLength with the strPadChar character, which defaults to a blank.
;
; Detlev Dalitz.20020209
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strMsgTitle = "Demo: udfStrOverlay (strNew, strTarget, intStart, intLength, strPadChar)"

:Test1
strT1 = "dark,edge of night,9,5,*"  ; change at end of strTarget       ; "edge of dark*"
strT2 = "dark,edge of night,1,4,*"  ; change at intStart of strTarget  ; "dark of night"
strT3 = "dark,edge of night,0,5,*"  ; no change                        ; "edge of night"
strT4 = "dark,edge of night,20,5,*" ; no change                        ; "edge of night"
strT5 = "dark,edge of night,-3,5,*" ; no change                        ; "edge of night"
strT6 = "dark,edge of night,3,0,"   ; no change                        ; "edge of night"
strT7 = "dark,edge of night,3,2,"   ; change                           ; "edda of night"
strT8 = ",edge of night,3,2,"       ; no change                        ; "edge of night"

For intItem = 1 To 8
   strNew     = ItemExtract (1, strT%intItem%, ",")
   strTarget  = ItemExtract (2, strT%intItem%, ",")
   intStart   = ItemExtract (3, strT%intItem%, ",")
   intLength  = ItemExtract (4, strT%intItem%, ",")
   strPadChar = ItemExtract (5, strT%intItem%, ",")
   strResult  = udfStrOverlay (strNew, strTarget, intStart, intLength, strPadChar)

   strMsgText = ""
   strMsgText = StrCat (strMsgText, 'strNew'    , @TAB, @TAB, '"', strNew    , '"', @LF)
   strMsgText = StrCat (strMsgText, 'strTarget' , @TAB, @TAB, '"', strTarget , '"', @LF)
   strMsgText = StrCat (strMsgText, 'intStart'  , @TAB, @TAB, '"', intStart  , '"', @LF)
   strMsgText = StrCat (strMsgText, 'intLength' , @TAB, @TAB, '"', intLength , '"', @LF)
   strMsgText = StrCat (strMsgText, 'strPadChar', @TAB, @TAB, '"', strPadChar, '"', @LF)
   strMsgText = StrCat (strMsgText, 'strResult' , @TAB, @TAB, '"', strResult , '"', @LF)
   Message (strMsgTitle, strMsgText)
Next


:Test2
BoxOpen ("Demo: udfStrOverlay (strNew, strTarget, intStart, intLength, strPadChar)","")
intTargetLength = 10
strTarget = StrFill ("-", intTargetLength)
For intLen = 1 To intTargetLength
   strOut = udfStrOverlay ("*", strTarget, intLen, 1, "")
   strOut = StrCat ("[", strOut, "]")
   BoxText (strOut)
   TimeDelay (0.2 / intTargetLength)
Next
For intLen = intTargetLength To 1 By -1
   strOut = udfStrOverlay ("*", strTarget, intLen, 1, "")
   strOut = StrCat ("[", strOut, "]")
   BoxText (strOut)
   TimeDelay (0.2 / intTargetLength)
Next
BoxShut ()


; Note: The user defined function udfStrOverlay has been made its task
; by the newly introduced native WinBatch function StrOverlay,
; first showing up in WB 2007B (DLL 5.13bem).
; StrOverlay (base-string, new-string, [pad-string [, start [, length]]])

:Test3
BoxOpen ("Demo: StrOverlay (strTarget, strNew, strPadChar, intStart, intLength)","")
intTargetLength = 10
strTarget = StrFill ("-", intTargetLength)
For intLen = 1 To intTargetLength
   strOut = StrOverlay (strTarget, "*", "", intLen, 1)
   strOut = StrCat ("[", strOut, "]")
   BoxText (strOut)
   TimeDelay (0.2 / intTargetLength)
Next
For intLen = intTargetLength To 1 By -1
   strOut = StrOverlay (strTarget, "*", "", intLen, 1)
   strOut = StrCat ("[", strOut, "]")
   BoxText (strOut)
   TimeDelay (0.2 / intTargetLength)
Next
BoxShut ()

Exit
;------------------------------------------------------------------------------------------------------------------------------------------