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 7 Years Ago by __avd: code tags

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.

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

Use Split method with StringSplitOptions.RemoveEmptyEntries option.

string[] variables= s.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
This article has been dead for over six months. Start a new discussion instead.