C#从逗号分隔的文本文件中读取到二维数组中 [英] C# Read from text file separated by commas into 2d array
本文介绍了C#从逗号分隔的文本文件中读取到二维数组中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前有这个:
using (StreamReader sr = new StreamReader("answers.txt")){for (iCountLine = 0; iCountLine <10; iCountLine++){for (iCountAnswer = 0; iCountAnswer <4; iCountAnswer++){sQuestionAnswers[iCountLine, iCountAnswer] =}}}
我的文本文件格式如下(10 行文本,每行 4 个项目,用逗号分隔):
<块引用>例子,例子,例子,例子123, 123, 123, 123
我不确定在 for 循环中的="之后需要什么才能读取文本文件的内容并将其拆分为二维数组.
解决方案
我不确定在 for 循环中的="之后需要什么
上面还缺少一行:
var tokens = sr.ReadLine().Split(',');
现在带有 =
的行看起来像这样:
sQuestionAnswers[iCountLine, iCountAnswer] = tokens[iCountAnswer];
I currently have this:
using (StreamReader sr = new StreamReader("answers.txt"))
{
for (iCountLine = 0; iCountLine < 10; iCountLine++)
{
for (iCountAnswer = 0; iCountAnswer < 4; iCountAnswer++)
{
sQuestionAnswers[iCountLine, iCountAnswer] =
}
}
}
My text file is formatted like this (10 lines of text, with 4 items on each line separated by commas):
example, example, example, example 123, 123, 123, 123
I'm not sure what I need after the "=" in the for loop to get it to read and split the contents of the text file into the 2D array.
解决方案
I'm not sure what I need after the "=" in the for loop
There's also a line missing above it:
var tokens = sr.ReadLine().Split(',');
Now the line with =
would look like this:
sQuestionAnswers[iCountLine, iCountAnswer] = tokens[iCountAnswer];
这篇关于C#从逗号分隔的文本文件中读取到二维数组中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文