Hello Ron,
Assuming you have a text file with one double per line you could do the following.
ArrayList nums = new ArrayList();
string filename = "";
if (File.Exists(filename))
{
using (TextReader tr = new StreamReader(filename))
{
string line;
while ((line = tr.ReadLine()) != null)
{
Double d;
if (Double.TryParse(line, out d))
nums.Add(d);
}
}
}
If you just have a text file with double delimited by white space perhaps using a regular expression to split them would be easist
if (File.Exists(filename))
{
using (TextReader tr = new StreamReader(filename))
{
string[] split = Regex.Split(tr.ReadToEnd(), @"(?m)\s+");
foreach (string num in split)
{
Double d;
if (Double.TryParse(num, out d))
nums.Add(d);
}
}
}
HTH
Wes Haggard
http://weblogs.asp.net/whaggard/ Managed to do it this way but it seems a bit long winded:
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
string TrainFileName = openFileDialog1.FileName;
if (File.Exists(TrainFileName))
{
StreamReader s = new StreamReader(TrainFileName);
ArrayList strs = new ArrayList();
string temp = null;
string st = s.ReadToEnd();
int strInd = 0;
for (int i = 0; i < st.Length; i++)
{
if ((st[i] >= '0' && st[i] <= '9')
|| st[i] == '.' || st[i] == '+'
|| st[i] == '-')
{
temp += st[i];
}
else
{
strs.Add(temp);
temp = null;
}
}
foreach(string a in strs)
{
double r;
if(double.TryParse(a,out r))
richTextBox1.Text += r.ToString() + '\n'; //
These
values will be assigned to an array of doubles
}
s.Close();
}
}