Imports System.IO
Imports System.Net
Imports System.Text.RegularExpressions

Public Class MainForm


    Private Sub CheckPage_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckPage.Click

        'Ok, get the page in a string variable
        Dim pageCode As String = String.Empty
        Dim myRequest As WebRequest = WebRequest.Create(Url.Text)
        myRequest.Method = WebRequestMethods.Http.Get
        Dim myResponse As WebResponse = myRequest.GetResponse
        Dim myStream As Stream = myResponse.GetResponseStream
        Dim encode As System.Text.Encoding = System.Text.Encoding.GetEncoding("utf-8")
        ' Pipe the stream to a higher level stream reader with the required encoding format.
        Dim readStream As New StreamReader(myStream, encode)
        Console.WriteLine(ControlChars.Cr + "Response stream received")
        Dim read(256) As [Char]
        ' Read 256 charcters at a time    .
        Dim count As Integer = readStream.Read(read, 0, 256)
        Console.WriteLine("HTML..." + ControlChars.Lf + ControlChars.Cr)
        'Loop through the lines
        While count > 0
            ' Dump the 256 characters on a string add to the file.
            Dim str As New [String](read, 0, count)
            pageCode += str
            count = readStream.Read(read, 0, 256)
        End While
        'trim off everything before <div id="VSProperty">
        pageCode = pageCode.Substring(pageCode.IndexOf(StartString.Text), pageCode.Length - pageCode.IndexOf("<div id=""VSProperty"">"))
        pageCode = pageCode.Substring(0, pageCode.IndexOf(EndString.Text))
        'Now I have the text, with tags, of the content.
        Dim stripped As String = Regex.Replace(pageCode, "<(.|\n)*?>", String.Empty)
        Dim counted As Array = Split(stripped, " ")
        NumberWords.Text = counted.Length
    End Sub
End Class
