[英]Stream Reader to double System.FormatException
我想將yahoo csv股票價格轉換為C#雙數組。 這是我的代碼:
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();
整數iStockTableRows是股票數量。 字符串sSymbols包含股票代號,它看起來像這樣:“ AAPL + MSFT”
CSV文件如下所示:
128.61
544.98
當我運行它時,System.FormatException發生在此行:
dCurrentPrice[iLine] = double.Parse(sr.ReadLine());
首先,它起作用了,由於某種原因,同樣的錯誤再次發生。 當我編寫sr.ReadLine()時,它不返回任何內容。
嘗試:
dCurrentPrice[iLine] = double.Parse(sr.ReadLine(), System.Globalization.CultureInfo.InvariantCulture);
也許您在非美國計算機上,使用不同的小數點分隔符。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.