Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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.
Posted

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).

Posted

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?

Posted

question lothos. . .

 

Who is writing the text file? is it generated by your app? or is it generated from some legacy application?

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.

Posted
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.
Here's what I'm up to.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...