0
float[] x = new float[10000];
 float[] y = new float[10000];
 int c=0;
            
            using (StreamReader sr = new StreamReader("e: \\CuPeak.dat"))
            {
                while (!sr.EndOfStream)
                {
                    string s = sr.ReadLine();         
                                                         
                    string[] variables = s.Split(' ');
                  x[c]  = float.Parse(variables[0]);//run time ERROR in this line " format exception was unhandled"
                    y[c] = float.Parse(variables[1]);
                    Console.WriteLine(x[0]);
                }
            }

Edited by __avd: code tags

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by __avd
0

This is probably caused by the variables[0] not being formatted as a float. To solve this you need to make sure that all the lines in the file actually contains "{float} {float}" on every single line.

0

This is probably caused by the variables[0] not being formatted as a float. To solve this you need to make sure that all the lines in the file actually contains "{float} {float}" on every single line.

no... thats not incorrect. i got it wheere i m wrong. the problem is in the textbox two integers are seperated by more than one space. And in my split funtion there is only one space (also i cant include more than 1 spce in split.) so, can u help plzzz

0

Use Split method with StringSplitOptions.RemoveEmptyEntries option.

string[] variables= s.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
This topic has been dead for over six months. 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.