Home » questions » Access text file at Visual Basic 2005?

Access text file at Visual Basic 2005?

2006-08-03 07:34:52, Category: Programming & Design
I can read while text file by System.io.steamreader.readtoend but I can not read a text file line by line . And also I can not change a word at a line for doing this I have to copy while text file to a string and change the word and copy it to file .

Answers

  1. Ali

    On 2006-08-05 16:36:20


    111111111111111111111111
  2. Just David

    On 2006-08-03 08:16:47


    Reading a text file line-by-line is straightforward. We can read each line with a ReadLine method. To determine whether we have reached the end of the file, we call the Peek method of the StreamReader object. The Peek method reads the next character in the file without changing the place that we are currently reading. If we have reached the end of the file, Peek returns -1. Listing B provides an example for reading a file line-by-line until the end of the file. To change a word at a line, split the line to an array against the space character. Every element of the array will then be a word from the line. Change the one you want then reasseble it to a line. Listing B oRead = oFile.OpenText(“C:\sample.txt”) While oRead.Peek <> -1 LineIn = oRead.ReadLine() End While oRead.Close()