Monday, March 26, 2012

Text file question

For example i have a file named textfile.txt Now what i want to do isthat i open that file and read first line(somestring =readline("textfile.txt"); or smth)then second and then third line. Howcan i do it.
VB.NET
Dim strReader as New FileStreamReader("textfile.txt")
While (you still want to read)
somestring = strReader.ReadLine()
DoSomethingWith_somestring
End While
strReader.Close()
- Dan
You could try this code:
int counter = 0;
string line;
// Read the file and display it line by line.
System.IO.StreamReader file =
new System.IO.StreamReader("c:\\test.txt");
while((line = file.ReadLine()) != null)
{
Console.WriteLine (line);
counter++;
}
file.Close();
// Suspend the screen.
Console.ReadLine();
This code is for a winform, but you can simply use it as you want.
regards

You will want to use the StreamReader class. Below is the link to MSDN.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemiostreamreaderclasstopic.asp
Got it all solved... Thank you for your help!

0 comments:

Post a Comment