-3
您好,我遇到的問題可以在下面的評論中看到。基本上我來到這裏的輸入格式不正確的點,我不明白爲什麼,下面也是我試圖把數據。輸入字符串格式不正確
的數據,
128,119,137,140,128,117,197 -0.5,0.0,0.5
125,129,136,130,125,162,125 -1.0,0.0,1.0
138,139,135,120,127,117,118 -0.5,0.0,0.5
127,149,138,160,122,217,137
149,129,140,140,129,127,126
153,159,130,140,127,112,126
147,129,130,148,128,137,134
任何人都可以看到爲什麼它不接受它?
TextReader tr = new StreamReader("c:/users/tom/documents/visual studio 2010/Projects/Exam/Exam/Data.txt");
for (var i = 0; i < 2; i++) // Ignores first two lines
{
String input = tr.ReadLine();
}
string remainingText = tr.ReadToEnd(); //Reads remained
string result = Regex.Replace(remainingText, @"\s+", ",");
char[] delimiterChars = {','}; //Establishes what should split the strings
string[] itemlist = (result.Split(delimiterChars)); //Splits the strings and puts them into itemlist
double[] values = new double[itemlist.Length]; //Creates an array the same size as itemlist
for (int i = 0; i < itemlist.Length; i++)
{
values[i] = (Convert.ToDouble(itemlist[i]));
//Attempts to convert the >values from itemlist into values ERROR, input string not in correct format
}
在哪裏數據? –
請解釋你在哪裏閱讀這個文件..?服務器或本地文件路徑在你的機器上?? – MethodMan
將這些數據編輯到您的帖子中。 – Blorgbeard