;------------------------------------------------------------------------------------------------------------------------------------------
If ItemLocate("udfstrtagfind",IntControl(77,103,0,0,0),@TAB) Then Goto skip_udfstrtagfind
#DefineFunction udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim)
If (sString=="") Then Return ("")
If (sBeginTag=="") Then sBeginTag = @LF
If (sEndTag=="") Then sEndTag = @CR
iTagMode = Min(1,Max(0,iTagMode))
sFindList = ""
iBBSize = 2+StrLen(sString)
hBB = BinaryAlloc(iBBSize)
BinaryPokeStr(hBB,0,@LF)
BinaryPokeStr(hBB,1,sString)
BinaryPokeStr(hBB,iBBSize-1,@CR)
sBBTag = BinaryTagInit(hBB,sBeginTag,sEndTag)
While 1
sBBTag = BinaryTagFind(sBBTag)
If (sBBTag=="") Then Break
iExtractBegin = BinaryTagIndex(sBBTag,iTagMode)
iExtractLen = BinaryTagLen(sBBTag,iTagMode)
iExtractEnd = iExtractBegin + iExtractLen
If (iExtractBegin==0) Then iExtractBegin = 1
If (iExtractEnd==iBBSize) Then iExtractLen = iExtractLen-2
sExtract = BinaryPeekStr(hBB,iExtractBegin,iExtractLen)
sFindList = ItemInsert(sExtract,-1,sFindList,sDelim)
EndWhile
iResult = BinaryFree(hBB)
Return (sFindList)
;..........................................................................................................................................
; This Function "udfStrTagFindStr" returns a string list sFindList
; which contains zero, one or more string items
; depending on the result of the search routine.
;
; sString ... The input string to be searched.
; sBeginTag ... The opening tag of the phrase to be found.
; sEndTag ... The closing tag of the phrase to be found.
; iTagMode=0 ... The tag find search routine returns the inner content of between the tags.
; iTagMode=1 ... The tag find search routine returns the enclosing tags too.
; sDelim ... Defines the separator character used to delimit the items in the sFindList.
;..........................................................................................................................................
; Detlev Dalitz.20020726
;------------------------------------------------------------------------------------------------------------------------------------------
#EndFunction
:skip_udfstrtagfind
;------------------------------------------------------------------------------------------------------------------------------------------
; --- test ---
sString = "This is a test string test."
sBeginTag = "his"
sEndTag = "string"
iTagMode = 0
sDelim = @TAB
sList1 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; " is a test "
sString = "This is a test string test."
sBeginTag = " "
sEndTag = " "
iTagMode = 0
sDelim = @TAB
sList2 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; "is@TABtest" (2 items).
sString = "This is a test string test."
sBeginTag = ""
sEndTag = "test"
iTagMode = 0
sDelim = @TAB
sList3 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; "This is a "
sString = "This is a test string test."
sBeginTag = "is"
sEndTag = ""
iTagMode = 0
sDelim = @TAB
sList4 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; " is a test string test."
sString = "This is a test string test."
sBeginTag = "a"
sEndTag = "g"
iTagMode = 1
sDelim = @TAB
sList5 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; "a test string"
sString = "Find HTML tags <b>like this one</b> in HTML strings."
sBeginTag = "<B>"
sEndTag = "</B>"
iTagMode = 0
sDelim = @TAB
sList6 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; "like this one"
sString = " This is a test string test. "
sBeginTag = " "
sEndTag = " "
iTagMode = 0
sDelim = @TAB
sList7 = udfStrTagFind (sString, sBeginTag, sEndTag, iTagMode, sDelim) ; "This@TABis@TABa@TABtest@TABstring@TABtest." (6 items).
Exit
;------------------------------------------------------------------------------------------------------------------------------------------
;*EOF*