Opening a text file

lothos12345

Well-known member
Joined
May 2, 2002
Messages
294
Location
Texas
Is there a way in VB.NET to open a text file to a specific section of text? For example say a user wants to all the contact information for a particuliar company I want the program to open that text file to that section of text. Not start at the top which gives the history of the company. Is there a way to accomplish this and if so could I get an example of how? Any help offered is greatly appreciated.
 
You can read the entire text file into a variable.

Code:
dim fs system.io.filestream
dim sr as system.io.streamreader

form_load()

fs = new filestream("C:\wherever\the\textfile\is.txt", filemode.open)
sr = new streamreader(fs)

dim TheFile as string
thefile = sr.readtoend()
sr.close
fs.close

end sub

Then you look through it to get the desired information (I would give you more there, but you didnt give me much to work with).
 
Sorry

So I read it into a variable, then how do I open the text file to the specfic section I am trying to look for? Example


Johnny
Amber
Lauren
Sam



I just want to open the text file to the section with the header of Lauren.
The header is bolded and all caps how do I accomplish this?
 
You can do either what thenerd suggested and then search the variable that the file is read into or read the textfile line by line until you get to the name you want, then read the data for that name. Theres no way to open the text file to the specific part that you want.
 
Back
Top