udfStrReplaceNC
str udfStrReplaceNC_1 (str, str, str)
str udfStrReplaceNC_2 (str, str, str)
str udfStrReplaceNC_3 (str, str, str)
;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrReplaceNC_1 (strBase, strOld, strNew)
intLenBase = StrLen (strBase)
intLenOld = StrLen (strOld)
intLenNew = StrLen (strNew)
intBBSize = intLenBase
If intLenNew > intLenOld Then intBBSize = intBBSize + StrCnt (strBase, strOld, 1, -1, 0) * (intLenNew - intLenOld)
hdlBB = BinaryAlloc (intBBSize)
BinaryPokeStr (hdlBB, 0, strBase)
BinaryReplace (hdlBB, strOld, strNew, @FALSE)
strOut = BinaryPeekStr (hdlBB, 0, BinaryEodGet (hdlBB))
hdlBB = BinaryFree (hdlBB)
Return strOut
;..........................................................................................................................................
; Adapted from
; Conf:  WinBatch
; From:  Marty marty+bbs@winbatch.com
; Date:  Thursday, May 16, 2002 01:01 PM
;..........................................................................................................................................
; Slighty modified by Detlev Dalitz.20020517.20090523.20110330.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrReplaceNC_2 (strBase, strOld, strNew)
intLenNew = StrLen (strNew)
intLenOld = StrLen (strOld)
intPos = 0
While @TRUE
   intPos = StrIndexNC (strBase, strOld, intPos, @FWDSCAN)
   If !intPos Then Break
   strBase = StrSub (strBase, 1, intPos - 1) : strNew : StrSub (strBase, intPos + intLenOld, -1)
   intPos = intPos + intLenNew
EndWhile
Return strBase
;..........................................................................................................................................
; Adapted from
; Conf:  WinBatch
; From:  billmeek winbatch@tfic.com
; Date:  Thursday, May 16, 2002 01:24 PM
;..........................................................................................................................................
; Slighty modified by Detlev Dalitz.20020517.20090523.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


;------------------------------------------------------------------------------------------------------------------------------------------
#DefineFunction udfStrReplaceNC_3 (strBase, strOld, strNew)
intLenNew = StrLen (strNew)
intLenOld = StrLen (strOld)
intPos = -intLenNew
While @TRUE
   intPos = StrIndexNC (strBase, strOld, intPos + intLenNew, @FWDSCAN)
   If !intPos Then Break
   strBase = StrSub (strBase, 1, intPos - 1) : strNew : StrSub (strBase, intPos + intLenOld, -1)
EndWhile
Return strBase
;..........................................................................................................................................
; Adapted from
; Conf:  WinBatch Script Exchange
; From:  lars doornbos l.m.doornbos@planet.nl
; Date:  Tuesday, March 29, 2011 11:35 PM
;..........................................................................................................................................
; Slighty modified by Detlev Dalitz.20110330.
;..........................................................................................................................................
#EndFunction
;------------------------------------------------------------------------------------------------------------------------------------------


; Test.

strBase = '"Hello Cat" the dog said to the CAT.'
strOld = "cat"
strNew = "Sammy"

strOut1 = udfStrReplaceNC_1 (strBase, strOld, strNew)
Message (strBase, strOut1)
; '"Hello Sammy" the dog said to the Sammy.'

strOut2 = udfStrReplaceNC_2 (strBase, strOld, strNew)
Message (strBase, strOut2)
; '"Hello Sammy" the dog said to the Sammy.'

strOut3 = udfStrReplaceNC_3 (strBase, strOld, strNew)
Message (strBase, strOut3)
; '"Hello Sammy" the dog said to the Sammy.'

Exit