Reading only numbers in CSV file C# -


i have csv file values:

 ,vb(m),ke23(m^-1), aaa,3.91e-06,2.21e+06 bbb,6.65e-03,3.50e+03 ccc,0.213,1503.759398 ddd,1.37e+00,0.00e+00 

i want read file , store number values in csv file.

i manipulating code featured here: http://www.codeproject.com/articles/415732/reading-and-writing-csv-files-in-csharp

or there easier way read , store numbers?

it's simple, loop on lines of file splitting on commas, loop on tokens using tryparse should work;

list<double> numbers = new list<double>(); double buffer = 0; while (string line = reader.readline() != null) {       string[] tokens = line.split(',');       foreach (string s in tokens)       {           if (double.tryparse(s, out buffer))               numbers.add(buffer);       } }  // print values iteration foreach (double d in numbers)      console.writeline(d.tostring());  // print linq numbers.select(x => console.writeline(x.tostring())); 

disclaimer: wrote code in browser hasn't been compiled or tested. minor adjustments might necessary that's pretty simplest way it.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -