Text file read line by line then convert to multiple strings
What i'm doing is saving things to a .txt file, each piece of information per line. (i.e. first name is on the first line, last name on the second line, email on the third line and so on) It then saves to a .txt file. What I want to do is read the .txt file and create a string for each line. So the first line would be one string and that string would have their first name in it. The second string would have their last name, the third string would have their email and so on. I also want to know if there is a better way for me to save data. Thanks.

Roei BarRank #1,271 · 1.4K reputationPosted Aug 30, 2009, 12:56 PM EDT
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) { mylines,Add(line); counter++; } file.Close();that will give you all lines in a collection of strings :-)
dont forget to mark this as "Accepted Answer"
Will Green5 reputationPosted Aug 30, 2009, 1:04 PM EDT
Will Green5 reputationPosted Aug 30, 2009, 1:47 PM EDT
Jan MontanoRank #1,295 · 1.3K reputationPosted Aug 30, 2009, 9:53 PM EDT
{
loadFile.Filter = "Text files|*.txt";
loadFile.FileName = "";
DialogResult dialogResult = loadFile.ShowDialog();
if (dialogResult == DialogResult.OK)
{
string getFile = loadFile.FileName;
StreamReader stream = new StreamReader(getFile);
string fileContent = stream.ReadToEnd();
string[] fileLines = fileContent.Split('\n');
stream.Close();
MessageBox.Show(fileLines[0], "First Name");
MessageBox.Show(fileLines[1], "Last Name");
MessageBox.Show(fileLines[2], "Email Address");
}
//file.Close();
}