string[] words;
numOfMatrix = int.Parse(fileIn.ReadLine());
nameOfMatrix1 = fileIn.ReadLine();
words = fileIn.ReadLine().Split(' ');
matrix1H = int.Parse(words[0]);
matrix1W = int.Parse(words[1]);
matrix1 = new int[matrix1H + 1, matrix1W + 1];
for (int i = 1; i <= matrix1H; i++)
{
int k = 0;
words = fileIn.ReadLine().Split(' ');
for (int j = 1; j <= matrix1W; j++)
{
matrix1[i,j] = int.Parse(words[k]);
k++;
}
}
输入采样数据解析字符串数组转换成int矩阵
3
Matrix One
5 7
45 38 5 56 18 34 4
87 56 23 41 75 87 97
45 97 86 7 6 8 85
67 6 79 65 41 37 4
7 76 57 68 8 78 2
Matrix Two
6 8
45 38 5 56 18 34 4 30
87 56 23 41 75 87 97 49
45 97 86 7 6 8 85 77
67 6 79 65 41 37 4 53
7 76 57 68 8 78 2 14
21 18 46 99 17 3 11 73
Matrix Three
6 6
45 38 5 56 18 34
87 56 23 41 75 87
45 97 86 7 6 8
67 6 79 65 41 37
7 76 57 68 8 78
21 18 46 99 17 3
未处理的异常:System.FormatException:输入字符串的不正确的格式。 在System.Number.StringToNumber(字符串str的NumberStyles选项,NumberBuffer &数的NumberFormatInfo信息,布尔parseDecimal) 在System.Number.ParseInt32(字符串s的NumberStyles风格的NumberFormatInfo信息) 在System.Int32.Parse(字符串s)
在我分析单词[k]到matrix1 [i,j]的行上,我收到一条错误消息。解析工作正常,我第一次使用单词[]但不是第二次我读东西英寸
什么是输入文件?你会得到什么错误? –
未处理的异常:System.FormatException:输入字符串的格式不正确。 – MDub
为了清晰起见,你应该把你正在进入问题本身的错误信息。你也应该澄清一下,如果这个样本数据是样本输出还是输入? – leigero