VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Remove HTML + Optional Ingnore Tags

by David Garske (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Advanced
Date Added: Wed 3rd February 2021
Rating: (4 Votes)

This function will strip a string of all html. An optional parameter (sIgnoreTags) allows specified HTML tags to be ignored from stripping.

Rate Remove HTML + Optional Ingnore Tags

Function RemoveHTML(ByVal sHTML, ByVal sIgnoreTags)
Dim I, J, arr_sIgnoreTags, sIgnoreTag, bIgnoreTags, bIgnoreTag, iIndex
bIgnoreTags = False
If Len(sIgnoreTags) > 0 Then
arr_sIgnoreTags = Split(sIgnoreTags, ",")
bIgnoreTags = True
End If
sHTML = Trim(sHTML)
If IsNull(sHTML) Then sHTML = ""
sHTML = Replace(sHTML, vbCrLf, "") 'Makes easier
I = InStr(1, sHTML, "<")
Do While I <> 0
bIgnoreTag = False
If bIgnoreTags Then
For iIndex = 0 To UBound(arr_sIgnoreTags)
sIgnoreTag = Trim(arr_sIgnoreTags(iIndex))
If UCase(Mid(sHTML, I + 1, Len(sIgnoreTag))) = UCase(sIgnoreTag) Then
bIgnoreTag = True
Exit For
End If
Next
End If

If Not bIgnoreTag Then
J = InStr(I + 1, sHTML, ">")
If J <> 0 Then
sHTML = Left(sHTML, I - 1) & Mid(sHTML, J + 1)
Else
'Chop off rest off sHTML since bad HTML
sHTML = Left(sHTML, I - 1)
End If
Else
I = I + 1 'So next tag is searched
End If
I = InStr(I, sHTML, "<")
Loop
If Len(sHTML) = 0 Then sHTML = " "
RemoveHTML = sHTML
End function

Download this snippet    Add to My Saved Code

Remove HTML + Optional Ingnore Tags Comments

No comments have been posted about Remove HTML + Optional Ingnore Tags. Why not be the first to post a comment about Remove HTML + Optional Ingnore Tags.

Post your comment

Subject:
Message:
0/1000 characters