Need to extract data from a text file

shurb

Member
Joined
Oct 9, 2007
Messages
16
Programming Experience
1-3
Hi and sorry if this has been answered previously but here goes.

I have a text file, (or html), which can be fairly large at times. My goal is to extract specific lines but the location and number of lines can change. It can be anywhere from 10 to 100+ lines that I need to get on a daily basis. The only constant I have is the following at the beginning of each line that I want to extract:

ArrestAndCharges.aspx?FirstName

And once i can successfully do that I want to extract all text from the ? to </font>, (</font is not shown here.)

Any suggestions on how to iterate throught the text file to do that for each entry and grab the information?
 
Hello if I am getting what you want to do correctly, can't you import the data into a richtextbox, then once there use the split command to split by the heading you indicated and then you would have your data?
 
True

I am displaying the data in a text box so you are saying I can use a split command to accomplish what I am looking for?
 
Using a richtextbox even if its an invisible one would be a good way just because it has a command that lets you load text from a text file built into it. Even if you used that you could then just set the textbox's text to it or something. I have used the split command to do similar things before. I have a program that gets your external ip from ipchicken.com and displays it but as a similar problem you are facing I had to sort through all the code it gives you so its just left with an ip. I did this using a series of split commands so yes it would work.
 
This is quite a good opportunity to use A Regex (or Regular Expression) It'll do exactly what you what in this scenario, not to say that string.split won't, but for instances like this I think that a Regex is cleaner. I'll try to knock one up and i'll post it back.
 
Any suggestions on how to iterate throught the text file to do that for each entry and grab the information?


VB.NET:
Dim lineStart as String = "ArrestAndCharges.aspx?FirstName"
For Each line As String In System.IO.File.ReadAllLines([B]path to file[/B])
  If line.StartsWith(lineStart) Then
    Dim start as Integer = line.IndexOf("?")
    Dim length as Integer = line.LastIndexOf("</font>") - start
    MessageBox.Show(line.SubString(start, length))
  End If
Next line
 
Back
Top