Reputation:
I want to convert yahoo csv stock prices to a C# double array. This is my code:
WebRequest wrPrice = WebRequest.Create("http://finance.yahoo.com/d/quotes.csv?s=" + sSymbols + "&f=a"); //sSymbols zb. "AAPL+GOOG+MSFT"
WebResponse wResp = wrPrice.GetResponse();
StreamReader sr = new StreamReader(wResp.GetResponseStream());
double[] dCurrentPrice = new double[iStockTableRows];
int iLine = 0;
while (sr.Peek() >= 0)
{
dCurrentPrice[iLine] = double.Parse(sr.ReadLine());
iLine++;
}
sr.Close();
The integer iStockTableRows is the amount of stocks. The string sSymbols contains the stock symbols, it can look like this: "AAPL+MSFT"
The CSV file looks like this:
128.61
544.98
When I run it System.FormatException occurs in this line:
dCurrentPrice[iLine] = double.Parse(sr.ReadLine());
First it worked and for some reason the same error occurs again. When I write sr.ReadLine() it doesn't return anything.
Upvotes: 0
Views: 360
Reputation: 111890
Try:
dCurrentPrice[iLine] = double.Parse(sr.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);
Perhaps you are on a non-US computer, with a different decimal separator.
Upvotes: 1