README.md

December 4, 2022 ยท View on GitHub

Strip HTML tags

Description

This following function takes an HTML page and strips it of all tags.

More Info

Submitted On
ByTmess
LevelUnknown
User Rating3.0 (9 globes from 3 users)
CompatibilityVB 5.0, VB 6.0
CategoryString Manipulation
WorldVisual Basic
Archive File

Source Code

Public Function ReplaceTags(varName As String) As String
'Will check each character for it "& n b s p;" without the spaces
'If it exists, skip it
'Will strip HTML tags and characters
Dim i As Double, varHold As String
Dim checkval As String, holdVal As String
 For i = 1 To Trim(Len(varName))
 checkval = Mid(varName, i, 6)
 holdVal = Mid(varName, i, 1)
 If checkval = "This page won't allow "& n b s p;" Then
  'So just remove the spaces
 i = i + 5
 GoTo LabelNext
 End If
 If holdVal = "<" Then
 Do Until holdVal = ">"
 i = i + 1
 holdVal = Mid(varName, i, 1)
 Loop
 holdVal = ""
 End If
 If holdVal = "%" Then
 Do Until holdVal = "%"
 i = i + 1
 holdVal = Mid(varName, i, 1)
 Loop
 holdVal = ""
 End If
 varHold = varHold & holdVal
LabelNext:
 Next i
ReplaceTags = varHold
End Function
Create a form and place two richtext box controls on it and a command button:
RichTextBox1
RichTextBox2
Command1
Now call it like the following:Assuming HTML is in Richtextbox1
Private Sub Command1_Click()
 Me.RichTextBox2 = ReplaceTags(Me.RichTextBox1)
End Sub