BinaryTagInit

Initializes a binary tag operation.

Syntax:

BinaryTagInit ( handle, start-tag, end-tag )

Parameters:

(i) handle: Handle of buffer. (handle returned from BinaryAlloc).

(s) start-tag: Specifies what beginning string (tag) to search for ( i.e. "{{" )

(s) end-tag: Specifies what ending string (tag) to search for ( i.e. "}}" )

Returns:

(s) returns a binary tag structure string, or "" on failure.

 

Note: This function is useful for editing HTML.

It searches the buffer for the start and end tags and returns a binary tag structure string that is used with the other binary tag functions.

 

Example:


;BinaryTag Example 1 - Basic Code
;Set up test case
;Setup input and output file names
filedata=StrCat(DirGet(),"filedata.txt")
filerslt=StrCat(DirGet(),"filerslt.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,"{{","}}")
;Not necessary in this example, but allows reuse of a
;BinaryBuffer if this code is placed in a loop editing
;multiple files.
BinaryEodSet(bb,0)
;Read data into the BinaryBuffer
BinaryRead(bb,filedata)
While 1
   structure=BinaryTagFind(structure)
   If structure=="" Then Break ; All done
   keyword=BinaryTagExtr(structure,1)
   Value="???" ; keyword not found error value
   If keyword=="date" Then Value=TimeDate()
   If keyword=="name" Then Value="Ms. Jamie Dough"
   If keyword=="product" Then Value="Analog Osscilosophilator"
   If keyword=="salesperson" Then Value="Fred Ficklemeyer"
   If keyword=="salespersonphone" Then Value="888.555.1234"
   structure = BinaryTagRepl(structure,Value)
EndWhile
BinaryWrite(bb,filerslt)
BinaryFree(bb)
Message("Result in",filerslt)
See Also:

BinaryTagFind, BinaryTagExtr, BinaryTagRepl