File.Not.Found
March 25th, 2009, 02:08 AM
Hi there, I was wondering if anybody could give me a hand.
I would like StreamReader to read each line of a .csv file (each line is made of 3 comma separated values), then create a String for each line read, and finally split each String into Substrings for further manipulation.
This is my code:
StreamReader reader("INPUT.csv");
String ^line = reader.ReadLine();
while (line != nullptr)
{
array<String^> ^cell = line->Split(',');
// deal with array here
int i = 0;
line = reader.ReadLine();
String^ StrValue0 = cell[i];
String^ StrValue1 = cell[i++];
String^ StrValue2 = cell[i++];
double Value0 = double:: Parse( StrValue0 );
textBox0->Text= Value0.ToString("N0");
double Value1 = double:: Parse( StrValue1 );
textBox1->Text= Value1.ToString("N0");
double Value2 = double:: Parse( StrValue2 );
textBox2->Text= Value2.ToString("N0");
}
The problem with this code is that StreamReader reads all the values present in the .csv files up to the end of the file and keeps in memory only the last line. What I would need instead is a command to stop ReadLine() at the end of each line, so that I can return each substring separately, starting from line 1.
Any advice is welcome.
I would like StreamReader to read each line of a .csv file (each line is made of 3 comma separated values), then create a String for each line read, and finally split each String into Substrings for further manipulation.
This is my code:
StreamReader reader("INPUT.csv");
String ^line = reader.ReadLine();
while (line != nullptr)
{
array<String^> ^cell = line->Split(',');
// deal with array here
int i = 0;
line = reader.ReadLine();
String^ StrValue0 = cell[i];
String^ StrValue1 = cell[i++];
String^ StrValue2 = cell[i++];
double Value0 = double:: Parse( StrValue0 );
textBox0->Text= Value0.ToString("N0");
double Value1 = double:: Parse( StrValue1 );
textBox1->Text= Value1.ToString("N0");
double Value2 = double:: Parse( StrValue2 );
textBox2->Text= Value2.ToString("N0");
}
The problem with this code is that StreamReader reads all the values present in the .csv files up to the end of the file and keeps in memory only the last line. What I would need instead is a command to stop ReadLine() at the end of each line, so that I can return each substring separately, starting from line 1.
Any advice is welcome.