Saturday, January 04, 2014

VB function : Clean Up / Remove HTML XML code from String

This function is removing all HTML/XML code from some string.
Private Function CodeClean(ByVal DStr As String) As String
Dim i As Long, j As Long
Dim Chr1 As String, Chr2 As String
Dim FlBol As Boolean
  Chr1 = "<"
  Chr2 = ">"

  If InStr(DStr, Chr1) > 0 Then FlBol = True Else FlBol = False
 
  Do Until FlBol = False
    i = 0
    j = 0
    i = InStr(DStr, Chr1)
    j = InStr(DStr, Chr2)
    If i > 0 And j = 0 Then
      j = Len(DStr)
    End If
    DStr = Left(DStr, i - 1) & Right(DStr, Len(DStr) - j)
    If InStr(DStr, Chr1) > 0 Then FlBol = True Else FlBol = False
  Loop
  Code Clean = DStr
End Function

You may change variables Chr1 & Chr2 to fit your need.

No comments :