Hi,
I've previously received help here with parsing a text file that contains the output of a traceroute. Here's the code I have so far:
I have two current problems - it is giving me an ArgumentOutOfRangeException at the line 'data = parseLine(textArray(i))' near the bottom - I am trying to get it to read out each of the lines that are stored, with the potential that there is a variable number stored. I thought I catered for this with this: 'For i = 4 To textArray.Count', but evidently not. Where am I going wrong?Code:Private Function parseLine(ByVal str As String) As String() Dim data(5) As String Dim index As String Dim i As Integer Dim del(0) As Char del(0) = " " For i = 0 To 4 str = str.Trim() index = str.IndexOf(" ") If index <> -1 Then data(i) = str.Substring(0, index) str = str.Substring(index) Else data(i) = str.Substring(0) End If Next Return data End Function Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim fileReader As StreamReader Dim counter As Integer Dim data(5) As String Dim i As Integer ' This reads opens the file Try fileReader = New StreamReader("c:\147-110-250-100.txt") Catch MsgBox("Cannot find file") End Try Dim currentLine As String = "" 'Dim blankLineCounter As Integer = 0 Dim textArray As New ArrayList() counter = 1 'This will read in each line of the file, starting at 4 Try Do currentLine = fileReader.ReadLine() If Not currentLine Is Nothing Then If counter > 3 Then ' Do things here textArray.Add(currentLine) End If counter += 1 End If Loop Until currentLine Is Nothing fileReader.Close() Catch MsgBox("Error with file input") End Try 'This parses each line then returns the output to a text box For i = 4 To textArray.Count 'Checks if the line number is even or odd - only odd ones have text on them for some reason If ((i Mod 2) = 1) Then data = parseLine(textArray(i)) txtDisplay.Text = txtDisplay.Text & "Hop number: " & data(0) & vbCrLf txtDisplay.Text = txtDisplay.Text & "First time: " & data(1) & vbCrLf txtDisplay.Text = txtDisplay.Text & "Second time: " & data(2) & vbCrLf txtDisplay.Text = txtDisplay.Text & "Third time: " & data(3) & vbCrLf txtDisplay.Text = txtDisplay.Text & "Hostname: " & data(4) & vbCrLf & vbCrLf End If Next End Sub
The other problem is I want to stop reading in the data when it stops being about the actual results. Here's the file I'm currently reading from:
I want to miss off anything that isn't giving me information - for example I want to miss off the text at the start and the 'Trace complete.' at the end. How would I go about this?Code:Tracing route to ipsec.eskom.co.za [147.110.250.100] over a maximum of 30 hops: 1 <1 ms <1 ms <1 ms 146.87.49.1 2 <1 ms <1 ms 1 ms gw-salford.netnw.net.uk [194.66.21.150] 3 21 ms 1 ms 1 ms gw-nnw.core.netnw.net.uk [194.66.25.97] 4 1 ms <1 ms <1 ms 194.66.25.141 5 2 ms 1 ms 1 ms so-0-1-0.warr-sbr1.ja.net [146.97.42.169] 6 * 4 ms 5 ms so-0-2-0.read-sbr1.ja.net [146.97.33.109] 7 6 ms 6 ms 6 ms lond-scr4.ja.net [146.97.33.146] 8 6 ms 6 ms 6 ms po1-0.int-gw4.ja.net [146.97.35.134] 9 6 ms 7 ms 6 ms ldn-b3-pos10-0.telia.net [213.248.100.237] 10 6 ms 6 ms 6 ms verizon-118106-ldn-b3.telia.net [213.248.104.46] 11 7 ms 7 ms 7 ms so-1-2-0.TR2.LND2.ALTER.NET [146.188.4.41] 12 7 ms 7 ms 8 ms so-0-0-0.TR1.LND9.ALTER.NET [146.188.15.25] 13 7 ms 8 ms 8 ms so-0-0-0.IH2.LND9.ALTER.NET [146.188.2.46] 14 7 ms 7 ms 7 ms so-1-0-1.IR1.LND19.ALTER.NET [146.188.2.242] 15 8 ms 7 ms 7 ms at0-1-0.cr1.lnd19.alter.net [196.30.229.129] 16 33 ms 180 ms 179 ms s6-0-0.cr5.jnb6.alter.net [196.30.229.149] 17 196 ms 196 ms 200 ms srp5-0-0.gw3.jnb6.alter.net [196.30.156.5] 18 183 ms 215 ms 180 ms 196.31.45.182 19 182 ms 191 ms 180 ms ipsec.eskom.co.za [147.110.250.100] Trace complete.
Thanks.




Reply With Quote