Working with Multiple Pointers in Binary Buffers
Keywords: search replace binary buffers
Question:
Hello, I am having trouble getting a program to do what I need. I think I may be in too deep. I need to search a file for this string and then replace between the : to the / with my own number leaving intact the 001. I think my problem is that the charachters between the : and / can be different lengths.I really appreciate any help. Here are some search strings:
:25:07262464211000101 :28C:03689/001Answer:
Option #1: see the function BinaryReplace, it will handle keeping track of all the pointers for you...Option #2: Here's my version. Counting those BinaryBuffers pointers is a tricky business.
:Start Replace="900/" Tempfile="c:\incoming\logicin.txt" foundone=0 insize=FileSize(TempFile) outsize=insize*2 inbuffer= BinaryAlloc(insize) outbuffer=BinaryAlloc(outsize) BinaryRead(inbuffer, TempFile) outptr=0 inptr=0 while 1 ptr1=BinaryIndexNC(inbuffer,inptr,"07262464211000101",@fwdscan) ptr2=BinaryIndexNC(inbuffer,inptr,":28C:",@fwdscan) ptr3=BinaryIndexNC(inbuffer,ptr2,"/",@Fwdscan) If ptr1==0 || ptr2==0 || ptr3==0 then break foundone=1 BinaryCopy(OutBuffer,outptr,Inbuffer,inptr, ptr2+4-inptr+1) outptr=BinaryEODGet(OutBuffer) BinaryPokeStr(outbuffer,outptr,Replace) outptr=BinaryEODGet(OutBuffer) inptr=ptr3+1 endwhile ;write rest of buffer BinaryCopy(outbuffer,outptr,inbuffer,inptr,insize-inptr) BinaryWrite(outbuffer,"c:\incoming\logincout.txt") Message("All","Done")
Article ID: W14112Filename: Example of Keeping Track of Multiple Pointers.txt