parsing HTML programmatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • unklevo@gmail.com

    #1

    parsing HTML programmatically

    Is there an easy way to convert HTML that comes from database as a
    string into text and display it on winform...

    Thanks.

  • Mike Labosh

    #2
    Re: parsing HTML programmaticall y

    A year ago I wrote a spider that crawls around http://www.wtng.info and
    extracts all the country codes, country names, and telephone numbering
    information. I haven't looked at it since then, but I think this is the
    utility function I made that strips all HTML tags from a string leaving only
    the text:

    Use it like this:

    '...get your data first
    Dim htmlText As String = 'wherever you got your html text

    ' This will keep extra empty lines
    Dim textOnly As String = stripHTML(htmlT ext, True)

    ' This will remove [most] extra empty lines
    Dim textOnly As String = stripHTML(htmlT ext, False)

    For this function to compile, you must Import
    System.Text.Reg ularExpressions .

    Private Function stripHTML( _
    ByVal html As String, _
    ByVal keepCRLF As Boolean _
    ) As String

    ' isolates a value between HTML tags and other control chars

    Dim rxDrop As New Regex("(\<[^\>]+)\>(\r\n)*")
    Dim rxKeep As New Regex("(\<[^\>]+)\>")

    If keepCRLF Then
    Return rxKeep.Replace( html, "").Trim()
    Else
    Return rxDrop.Replace( html, "").Trim()
    End If

    End Function


    --
    Peace & happy computing,

    Mike Labosh, MCSD
    "Musha ring dum a doo dum a da!" -- James Hetfield
    <unklevo@gmail. com> wrote in message
    news:1124125277 .273220.232100@ g14g2000cwa.goo glegroups.com.. .[color=blue]
    > Is there an easy way to convert HTML that comes from database as a
    > string into text and display it on winform...
    >
    > Thanks.
    >[/color]


    Comment

    Working...