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]);
                }
            }

Recommended Answers

All 3 Replies

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.