Hello,
I'm fairly new to vb.net and am encountering a problem when trying to write data to a text file. If I put the output into a messagebox I can see it, but when I attempt to write it to a file it is just blank. What am I missing here? EDIT - This is just a simple winform that I specify a path to a local HTML file in Textbox1 and I'm attempting to parse some HREF tag data. Thanks in advance.
I'm fairly new to vb.net and am encountering a problem when trying to write data to a text file. If I put the output into a messagebox I can see it, but when I attempt to write it to a file it is just blank. What am I missing here? EDIT - This is just a simple winform that I specify a path to a local HTML file in Textbox1 and I'm attempting to parse some HREF tag data. Thanks in advance.
VB.NET:
Imports System.IO
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sr As New StreamReader(TextBox1.Text)
Dim input As String
Do
input = sr.ReadLine
If input IsNot Nothing Then
dumpHREF(input)
End If
Loop Until input Is Nothing
sr.Close()
End Sub
Sub dumpHREF(ByVal inputString As String)
Dim r As Regex
Dim m As Match
Dim sw As New StreamWriter("c:\html.txt")
r = New Regex(("href\s*=\s*(?:""(?<1>[^""]*)""|(?<1>\S+))"), RegexOptions.IgnoreCase Or RegexOptions.Compiled)
m = r.Match(inputString)
While m.Success
MessageBox.Show("found href " & m.Groups(1).Value & " at " & m.Groups(1).Index.ToString())
sw.WriteLine("found href " & m.Groups(1).Value & " at " & m.Groups(1).Index.ToString())
m = m.NextMatch
End While
sw.Close()
End Sub
End Class