Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: UDF StrReplace Ignore Case
#DefineFunction strReplaceNC(STRING, old, new) lo = StrLen(old) ln = StrLen(new) ptr = 1-ln While @TRUE ptr = StrIndexNC(STRING, old, ptr+ln, @FWDSCAN) If !ptr Then Break STRING = StrSub(STRING, 1, ptr-1):new:StrSub(STRING, ptr+lo, -1) EndWhile Return STRING #EndFunction rtv = strReplaceNC('Hello there, and again hello again', 'HELLO', 'Bye') Pause('',rtv)
#DefineFunction StrReplaceNC(DaString,old,new) len=StrLen(DaString) oldlen=StrLen(old) newlen=StrLen(new) bbsize=len If newlen>oldlen count=0 i=1 While @TRUE i=StrIndexNC(DaString,old,i,@FWDSCAN) If i==0 Then Break count=count+1 i=i+oldlen EndWhile bbsize=bbsize+(count*(newlen-oldlen)) EndIf bb=BinaryAlloc(bbsize) BinaryPokeStr(bb,0,DaString) BinaryReplace(bb,Old,new,@FALSE) ans=BinaryPeekStr(bb,0,BinaryEodGet(bb)) BinaryFree(bb) Return (ans) #EndFunction input=" Hello Cat the dog said to the cAt" oldx="cat" newx="Sam" output=StrReplaceNC(input,oldx,newx) Message(input,output)
Article ID: W15321
File Created: 2011:03:30:08:30:36
Last Updated: 2011:03:30:08:30:36