How to Insert a Delimiter Every 5 Characters
Keywords: binary
Question:
I have a file of numbers and I want to insert a delimiter every 5 characters.
How would I do that automatically with Winbatch?
Answer:
Something like the following. You'll need to turn Debug(1) on
and step through the code to polish it.
;debug(1)
fs1 = FileSize( "C:\TEMP\zFILETOPARSE.TXT" )
binbuf1 = BinaryAlloc( fs1 + 100 )
BinaryRead( binbuf1, "C:\TEMP\zFILETOPARSE.TXT" )
tempptr=5
For offset=0 to int(fs1/5.0);might need to adjust this
BoxOpen("Increment", int(fs1/5.0))
BinaryPokeStr( binbuf1, tempptr, "|")
tempptr = tempptr+6 ;this does it
;tempptr = tempptr+5 ;this inserts every 4 chars
Next
BinaryWrite( binbuf1, "C:\TEMP\zPARSEDFILE.TXT")
BinaryFree( binbuf1 )
Message("Parsing", "Done.")
Article ID: W12731
Filename: Insert a Delimiter Every 5 Chars.txt