输入字符串格式不正确



你好,我所遇到的问题可以在下面的评论中看到。基本上我到了输入格式不正确的地步,我看不出原因,下面也是我试图输入的数据。

数据,

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
}

添加StringSplitOptions.RemoveEmptyEntriesSplit

string[] itemlist = (result.Split(delimiterChars,StringSplitOptions.RemoveEmptyEntries));

相关内容

  • 没有找到相关文章

最新更新