Strip HTML using LotusScript

I needed a LotusScript routine to strip HTML out of some text I was importing from an ODBC data store. I did a quick Google search, and came up with a pretty nice start posted by Colin Williams. It wasn't "generic" enough for me, so I did a little work on it and came up with the following function and helper functions. Enjoy:
Function StripHTML (strSource As String, bool_StripOrphans As Boolean) As String
%REM
End Function ' StripHTML
This function will strip HTML tags from a passed in string,
and return the resulting string.
Orphan Tags ("<" & ">") will be handled based on the value of bool_StripOrphans.
The Orphan Tags will be removed if bool_StripOrphans is True,
and will be ignored otherwise.
%END REMand return the resulting string.
Orphan Tags ("<" & ">") will be handled based on the value of bool_StripOrphans.
The Orphan Tags will be removed if bool_StripOrphans is True,
and will be ignored otherwise.
Dim intPosOpen As Integer
Dim intPosClose As Integer
Dim strTarget As String
strTarget$ = strSource
If bool_StripOrphans Then
Dim intPosClose As Integer
Dim strTarget As String
strTarget$ = strSource
If bool_StripOrphans Then
' Strip out Orphan Tags
Do
Else
StripHTML$ = strTarget$
Do
intPosOpen% = Instr(strTarget$, "<")
intPosClose% = Instr(strTarget$, ">")
If (intPosOpen% < intPosClose%) Then
Loop While ((intPosOpen% + intPosClose%) > 0)intPosClose% = Instr(strTarget$, ">")
If (intPosOpen% < intPosClose%) Then
' Either the first open indicator occurs prior to the first close indicator,
' or doesn't exist at all.
If (intPosOpen% = 0) Then
Else
' or doesn't exist at all.
If (intPosOpen% = 0) Then
' The first open indicator doesn't exist.
' If the Orphan close indicator exists, then strip it out.
If (intPosClose% > 0) Then strTarget$ = StripFirstSubstr(strTarget$, ">")
Else
' If the Orphan close indicator exists, then strip it out.
If (intPosClose% > 0) Then strTarget$ = StripFirstSubstr(strTarget$, ">")
' The first open indicator exists, and occurs prior to the first close indicator.
' THIS INDICATES STANDARD MARKUP. STRIP IT OUT
strTarget$ = StripFirstSubstr(strTarget$, _
Mid$(strTarget$, intPosOpen%, (intPosClose% - intPosOpen%) + 1))
End If ' intPosOpen% = 0
' THIS INDICATES STANDARD MARKUP. STRIP IT OUT
strTarget$ = StripFirstSubstr(strTarget$, _
Mid$(strTarget$, intPosOpen%, (intPosClose% - intPosOpen%) + 1))
' Either the first close indicator occurs prior to the first open indicator,
' or doesn't exist at all.
If (intPosClose% = 0) Then
End If ' intPosOpen% < intPosClose%' or doesn't exist at all.
If (intPosClose% = 0) Then
' The first close indicator doesn't exist.
' If the Orphan open indicator exists, then strip it out.
If (intPosOpen% > 0) Then strTarget$ = StripFirstSubstr(strTarget$, "<")
Else' If the Orphan open indicator exists, then strip it out.
If (intPosOpen% > 0) Then strTarget$ = StripFirstSubstr(strTarget$, "<")
' The first close indicator occurs prior to the first open indicator,
' and is therefore an Orphan. Strip it out.
strTarget$ = StripFirstSubstr(strTarget$, ">")
End If 'intPosClose% = 0' and is therefore an Orphan. Strip it out.
strTarget$ = StripFirstSubstr(strTarget$, ">")
Else
' Orphan tags are to be ignored.
Do
End If ' bool_StripOrphansDo
intPosOpen% = Instr(strTarget$, "<")
If (intPosOpen% > 0) Then
If (intPosClose% > intPosOpen%) Then
Loop While ((intPosOpen% + intPosClose%) > 0)
If (intPosOpen% > 0) Then
' An open indicator exists. Find the subsequent close indicator
intPosClose% = Instr(intPosOpen, strTarget$, ">")
ElseintPosClose% = Instr(intPosOpen, strTarget$, ">")
' No open indicator exists. Set the close position to zero and bail out.
intPosClose% = 0
End If ' intPosOpen% > 0intPosClose% = 0
If (intPosClose% > intPosOpen%) Then
' The first open indicator exists, and occurs prior to the first close indicator.
' THIS INDICATES STANDARD MARKUP. STRIP IT OUT
strTarget$ = StripFirstSubstr(strTarget$, _
Mid$(strTarget$, intPosOpen%, (intPosClose% - intPosOpen%) + 1))
Else' THIS INDICATES STANDARD MARKUP. STRIP IT OUT
strTarget$ = StripFirstSubstr(strTarget$, _
Mid$(strTarget$, intPosOpen%, (intPosClose% - intPosOpen%) + 1))
' No close indicator exists. Set the open position to zero and bail out.
intPosOpen% = 0
End If ' intPosClose% > intPosOpen%
intPosOpen% = 0
StripHTML$ = strTarget$
Function StripFirstSubstr (strSource As String, strSubstr As String) As String
%REM
This function strips the first occurence of a substring from a string,
and returns the result.
If the substring is not contained within the source string,
this function returns the source string.
%END REM
If (Instr(strSource$, strSubstr$) > 0) Then
End Function ' StripFirstSubstr
This function strips the first occurence of a substring from a string,
and returns the result.
If the substring is not contained within the source string,
this function returns the source string.
%END REM
If (Instr(strSource$, strSubstr$) > 0) Then
StripFirstSubstr$ = Strleft(strSource$, strSubstr$) & Strright(strSource$, strSubstr$)
Else
StripFirstSubstr$ = strSource$
End If ' (Instr(strSource$, strSubstr$) > 0)
Comments
As a designer you know I am toooo lazy.
Posted by Els At 11:55:38 AM On 10/28/2008 | - Website - |
Posted by patrick picard At 02:54:26 PM On 11/24/2008 | - Website - |
-Devin.
Posted by Devin Olson At 06:30:00 AM On 11/25/2008 | - Website - |
-Devin.
Posted by Devin At 06:59:04 PM On 04/07/2005 | - Website - |