0

hi everyone I'm new to c# and working with file currently I need to read some string from the file but not the whole file so what functions can I use to read the file string by string ?

2
Contributors
16
Replies
17
Views
6 Years
Discussion Span
Last Post by alaa sam
Featured Replies
  • [CODE] //Declare and init variable of text reader and specify the file full path System.IO.TextReader tr = new System.IO.StreamReader("c:\\myFile.txt"); //check if file has data (not empty) //Peek() get the next char and return -1 if EOF if (tr.Peek() > -1) { //Read Line string line=tr.ReadLine(); } //Close the file tr.Close(); … Read More

  • yes it is just like MFC and Dialoge ic c++ Read More

0

Ok I want to read a line and compare it with some string is there's any function that read a line from text file ?

0
System.IO.TextReader tr = new System.IO.StreamReader("c:\\myFile.txt");
if (tr.Peek() > -1)
{
    string line=tr.ReadLine();
}
tr.Close();
1
//Declare and init variable of text reader and specify the file full path
System.IO.TextReader tr = new System.IO.StreamReader("c:\\myFile.txt");
//check if file has data (not empty)
//Peek() get the next char and return -1 if EOF
if (tr.Peek() > -1)
{    
//Read Line
string line=tr.ReadLine();
}
//Close the file
tr.Close();
0

ok thanks a lot this code will read a single line at each iteration till the end of the file
??

0

and I have another question little bit far from my first question , I used to program in c++ and I recently move to c# but I have never programmed windows application , so if I declared any class does it have to be inherited from Form ??

Edited by alaa sam: wrong spilling

0

so this means that I can create any classes as in console applications and use them ,

0

ok so I need to use forms for input and output and the rest is as in console applications ??

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.