
Returns the length of a binary tag.
BinaryTagLen( tag-struct, mode )
(s) tag-struct: Structure returned from BinaryTagInit.
(i) mode: 0 length of text; 1 length of text + tags
(s) the length of the text that was found.
Note: This function is useful for editing HTML.
This function can be used after a successful BinaryTagFind, to return the length of the text that was found. It must be used before any subsequent BinaryReplace, since BinaryReplace will change the tag structure.
;BinaryTag Advanced functions
;Note: The BinaryTagIndex and BinaryTagLen
;functions are not generally required or
;used by most scripts using the BinaryTag
;functions. That are provided for the
;unusual case of a requirement to mix
;normal Binary functions with BinaryTag
;functions.
;Set up test case
;Setup input and output file names
filedata=StrCat(DirGet(),"filedata.txt")
;Set up a sample file for this example.
;Presumably you could have a library of these
;to choose from, making form letters easy to
;automate.
fhandle=FileOpen(filedata,"WRITE")
FileWrite(fhandle,"{{date}}")
FileWrite(fhandle,"")
FileWrite(fhandle,"Dear {{name}}")
FileWrite(fhandle,"Thank you for your recent purchase of")
FileWrite(fhandle,"our new {{product}}.")
FileWrite(fhandle,"")
FileWrite(fhandle,"Please feel free to call if you have ")
FileWrite(fhandle,"any questions.")
FileWrite(fhandle,"")
FileWrite(fhandle,"{{salesperson}}")
FileWrite(fhandle,"{{salespersonphone}}")
FileClose(fhandle)
; Allocate a buffer much larger than required.
bb=BinaryAlloc(10000)
;Using {{ and }} for open and close tags around keywords
structure=BinaryTagInit(bb,"{{","}}")
;Read data into the BinaryBuffer
BinaryRead(bb,filedata)
While 1
structure=BinaryTagFind(structure)
If structure=="" Then Break ; All done
blen=BinaryTagLen(structure,1)
bindex=BinaryTagIndex(structure,1)
keyword=BinaryTagExtr(structure,1)
Pause("After find",StrCat(keyword,@CRLF,"len=",blen,@CRLF,"index=",bindex))
structure = BinaryTagRepl(structure,"dummy data")
blen=BinaryTagLen(structure,1)
bindex=BinaryTagIndex(structure,1)
Pause("After replace",StrCat(keyword,@CRLF,"len=",blen,@CRLF,"index=",bindex))
EndWhile
BinaryFree(bb)
Exit