euverve's Profile User Rating: -----

Reputation: 0 Apprentice
Group:
Contributors
Active Posts:
5 (0 per day)
Joined:
09-February 09
Profile Views:
343
Last Active:
User is offline Dec 15 2011 03:31 AM
Currently:
Offline

Previous Fields

Dream Kudos:
25

Latest Visitors

Icon   euverve has not set their status

Posts I've Made

  1. In Topic: How to extract dates from web page

    Posted 14 Dec 2011

    I have done the same thing as yours. I want to know how to apply regular expressions and to avoid lengthy codes.

    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            MsgBox(getcurrentdate())
        End Sub
    
        Public Function getcurrentdate() As String
            Try
                Dim sData = readpage("http://www.whatsthedatetoday.com/")
    
                'Process HTML source removing tags
                Dim str As String = sData
                sData = Mid(str, str.IndexOf("oday's Date is:"), str.IndexOf("The Date on your Computer is:"))
    
                Dim Data = sData.IndexOf("GMT")
                sData = CleanSpace(StripHTMLTags(Mid(sData, 1, Data)))
    
                sData = Replace(sData, " th ", "", 1)
                sData = Replace(sData, " st ", "", 1)
                sData = Replace(sData, " nd ", "", 1)
                sData = Replace(sData, " rd ", "", 1)
                sData = Replace(sData, "  ", "", 1)
    
                Dim tab As Char = ControlChars.Tab
                TextBox1.Text = Replace(sData, tab.ToString(), "", 1)
    
                'Cleanup Unused Lines
                TextBox1.Lines = sData.Split(New Char() {ControlChars.Lf}, StringSplitOptions.RemoveEmptyEntries)
    
                Dim strLen As Integer
                For i As Integer = 0 To TextBox1.Lines.Length - 1
                    If TextBox1.Lines(i).Contains("Monday") Or _
                        TextBox1.Lines(i).Contains("Tuesday") Or _
                        TextBox1.Lines(i).Contains("Wednesday") Or
                        TextBox1.Lines(i).Contains("Thursday") Or _
                        TextBox1.Lines(i).Contains("Friday") Or _
                        TextBox1.Lines(i).Contains("Saturday") Or _
                        TextBox1.Lines(i).Contains("Sunday") Then
                        strLen = Len(TextBox1.Lines(i).ToString)
                    End If
                Next
                Return Mid(sData.Remove(0, strLen), 1, strLen - 1)
            Catch ex As Exception
                Return ""
            End Try
        End Function
    
        'Get Source of the HTML page
        Public Shared Function readpage(ByVal url As String) As String
            Dim Str As System.IO.Stream
            Dim srRead As System.IO.StreamReader
            Try
                ' make a Web request
                Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url)
                Dim resp As System.Net.WebResponse = req.GetResponse
                Str = resp.GetResponseStream
                srRead = New System.IO.StreamReader(Str)
    
                ' read all the text 
                Dim Data As String = srRead.ReadToEnd
                Return Data
            Catch ex As Exception
                Return "Unable to download content"
            End Try
        End Function
    
        'Remove HTML Tags
        Public Shared Function StripHTMLTags(ByVal HTMLToStrip As String) As String
            Dim stripped As String
            If HTMLToStrip <> "" Then
                stripped = System.Text.RegularExpressions.Regex.Replace(HTMLToStrip, "<(.|\n)+?>", " ")
                Return stripped
            Else
                Return ""
            End If
        End Function
    
        'Remove Double Spaces
        Public Shared Function CleanSpace(ByVal strIn As String) As String
            ' // Remove leading or trailing spaces
            strIn = Trim(strIn)
            ' // Replace all double space pairings with single spaces
            Do While InStr(strIn, "  ")
                strIn = Replace(strIn, "  ", " ")
            Loop
            ' // Return the result
            CleanSpace = strIn
        End Function
    End Class
    
    
    


    Is there anyway to utilize the code without the need of textbox?

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

euverve hasn't added any friends yet.

Comments

euverve has no profile comments yet. Why not say hello?