Reading values from specified line from a text file [modified]
-
Hi all, i am working as a software eng..let know that how to read values from a text file at specified location which the file consists of no of lines of code...moreover i want to code in c#.net for example.. 1 23.34 2 456.33 --- i want to read values below 1 n 2 as x,y values...so plz let me know how to do.. Thanks in advance... Regards, cnr.. -- modified at 1:26 Friday 11th August, 2006
-
Hi all, i am working as a software eng..let know that how to read values from a text file at specified location which the file consists of no of lines of code...moreover i want to code in c#.net for example.. 1 23.34 2 456.33 --- i want to read values below 1 n 2 as x,y values...so plz let me know how to do.. Thanks in advance... Regards, cnr.. -- modified at 1:26 Friday 11th August, 2006
Just discard any lines you don't want, I assume you want to read in the alternate lines. In this case something like which follows should work.
// Open the StreamReader
using (StreamReader sr = new StreamReader(filename))
{
// Loop until the EOF
while(sr.Peek() != -1)
{
// Discard the odd lines
sr.ReadLine();
// Read in the even lines for processing
string line = sr.ReadLine();
// Process Line here
}
// Close stream
sr.Close();
}
Formula 1 - Short for "F1 Racing" - named after the standard "help" key in Windows, it's a sport where participants desperately search through software help files trying to find actual documentation. It's tedious and somewhat cruel, most matches ending in a draw as no participant is able to find anything helpful. - Shog9 Ed
-
Hi all, i am working as a software eng..let know that how to read values from a text file at specified location which the file consists of no of lines of code...moreover i want to code in c#.net for example.. 1 23.34 2 456.33 --- i want to read values below 1 n 2 as x,y values...so plz let me know how to do.. Thanks in advance... Regards, cnr.. -- modified at 1:26 Friday 11th August, 2006
XML or ini files ? The way you do it is not readable for any other programmer, if anyone want to edit your code or has to take over your project, they will have a hard time to learn what that file stands for ... In XML or ini you can at least comment (in your code, or in the text file itself).
Don't you also love the code?