Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

HTMLDecodeEx - Decodes HTML encoded strings

Total Hit ( 2447)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


Click here to copy the following block
' Decodes HTML encoding applied to the specified Text and returns the result
' Optionally specify if we encoded a HREF link and the character
' used for encoding - the default is the standard ampersand

' i.e. Call MsgBox(HTMLDecodeEx("<Sample HTML Decoded Text>"
' & ""))

Public Function HTMLDecodeEx(ByVal Text As String, Optional ByVal vfHREFDecode _
  As Boolean = False, Optional ByVal vstrAmpChar As String = "&") As String
  
  Dim astrTokens() As String
  Dim lngTotal As Long
  Dim lngCount As Long
  Dim strToken As String
  Dim strCode As String
  Dim lngPos As Long
  Dim astrReturn() As String
  Dim strReturn As String
  
  strReturn = Text
  
  If Trim$(strReturn) <> "" Then
    ' tokenize the text
    astrTokens = Split(Text, vstrAmpChar, -1, vbTextCompare)
      
    lngTotal = UBound(astrTokens)
    
    ' create enough space for the return
    ReDim astrReturn(lngTotal)
    
    For lngCount = 0 To lngTotal
      ' look for the end of the token
      strToken = astrTokens(lngCount)
      lngPos = InStr(1, strToken, ";", vbTextCompare)
      If (lngPos = 0) Then
        astrReturn(lngCount) = strToken
      Else
        strCode = Mid$(strToken, 1, lngPos)
        Select Case strCode
          Case "nbsp;"
            astrReturn(lngCount) = " " & Mid$(strToken, lngPos + 1)
          Case "quot;"
            astrReturn(lngCount) = """" & Mid$(strToken, lngPos + 1)
          Case "amp;"
            astrReturn(lngCount) = vstrAmpChar & Mid$(strToken, _
              lngPos + 1)
          Case "lt;"
            astrReturn(lngCount) = "<" & Mid$(strToken, lngPos + 1)
          Case "gt;"
            astrReturn(lngCount) = ">" & Mid$(strToken, lngPos + 1)
          Case Else
            ' see if it's
            If Left$(strToken, 1) = "#" Then
              astrReturn(lngCount) = Chr$(Mid$(strToken, 2, _
                lngPos - 2)) & Mid$(strToken, lngPos + 1)
            Else
              astrReturn(lngCount) = strToken
            End If
        End Select
      End If
    Next ' lngCount
    
    Erase astrTokens
    
    strReturn = Join(astrReturn, "")
  
    Erase astrReturn
  End If
  
  HTMLDecodeEx = strReturn
  
End Function


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.