lothos12345 Posted July 11, 2005 Posted July 11, 2005 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. Quote
thenerd Posted July 11, 2005 Posted July 11, 2005 You can read the entire text file into a variable. 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 didn't give me much to work with). Quote
lothos12345 Posted July 11, 2005 Author Posted July 11, 2005 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? Quote
Joe Mamma Posted July 11, 2005 Posted July 11, 2005 question lothos. . . Who is writing the text file? is it generated by your app? or is it generated from some legacy application? Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
lothos12345 Posted July 11, 2005 Author Posted July 11, 2005 Answer It is already generated for us by a legacy application. Quote
Machaira Posted July 12, 2005 Posted July 12, 2005 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. There's no way to open the text file to the specific part that you want. Quote Here's what I'm up to.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.