EDN Admin
Well-known member
I am trying to read data values from a text file and ive been able to open the file and read it to an array but I dont want the title and header text that is in the file. I dont want to delete the header and title though so I want to know how to specify
a line to start at when using StreamReader so I can skip this information. my program currently opens and reads the file and puts the data into an array splitting it with ;.
I appreciate the help, Thanks
edit:
here is an example of my C# code:
<pre class="prettyprint // open EQE data text file and put it into an array
Stream myStream2 = null;
OpenFileDialog openFileDialog2 = new OpenFileDialog();
openFileDialog2.InitialDirectory = "Desktop";
openFileDialog2.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog2.FilterIndex = 2;
openFileDialog2.RestoreDirectory = true;
openFileDialog2.Multiselect = false;
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream2 = openFileDialog2.OpenFile()) != null)
{
using (myStream2)
{
try
{
using (StreamReader sr = new StreamReader(openFileDialog2.FileName))
{
string EQED = sr.ReadLine();
string[] midEQEData = EQED.Split(;
var EQEData = Convert.ToDouble(midEQEData);
}
}
catch (Exception err)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(err.Message);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
textBox2.Text = openFileDialog2.FileName;
}[/code]
<br/>
<br/>
View the full article
a line to start at when using StreamReader so I can skip this information. my program currently opens and reads the file and puts the data into an array splitting it with ;.
I appreciate the help, Thanks
edit:
here is an example of my C# code:
<pre class="prettyprint // open EQE data text file and put it into an array
Stream myStream2 = null;
OpenFileDialog openFileDialog2 = new OpenFileDialog();
openFileDialog2.InitialDirectory = "Desktop";
openFileDialog2.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog2.FilterIndex = 2;
openFileDialog2.RestoreDirectory = true;
openFileDialog2.Multiselect = false;
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream2 = openFileDialog2.OpenFile()) != null)
{
using (myStream2)
{
try
{
using (StreamReader sr = new StreamReader(openFileDialog2.FileName))
{
string EQED = sr.ReadLine();
string[] midEQEData = EQED.Split(;
var EQEData = Convert.ToDouble(midEQEData);
}
}
catch (Exception err)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(err.Message);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
textBox2.Text = openFileDialog2.FileName;
}[/code]
<br/>
<br/>
View the full article