EDN Admin
Well-known member
im having trouble, I am trying to read from a text file and then put the data from the file into a double array but with what i wrote it reads the file and puts it into a 1D string array.
an example of the text follow is as follows:
title
number data;number data
number data;number data
etc.
what I want is for the program to read the text file, and put the number before the ; in [0,0] and the number after the ; in [0,1] then the next line before the ; is in [1,0] and after the ; is in [1,1]
so i guess what im asking is what should i replace the following code with so that it does what i said above
<pre class="prettyprint 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))
{
sr.ReadLine();//to skip the title
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);
}[/code]
<br/>
View the full article
an example of the text follow is as follows:
title
number data;number data
number data;number data
etc.
what I want is for the program to read the text file, and put the number before the ; in [0,0] and the number after the ; in [0,1] then the next line before the ; is in [1,0] and after the ; is in [1,1]
so i guess what im asking is what should i replace the following code with so that it does what i said above
<pre class="prettyprint 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))
{
sr.ReadLine();//to skip the title
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);
}[/code]
<br/>
View the full article