【发布时间】:2015-10-12 03:23:54
【问题描述】:
我正在尝试为一个学校项目编写一个程序,该程序将读取每行包含一个名称的 csv 文件,并输出每个名称及其在列表框中出现的次数。我不希望它预先设置为特定名称,但我想这也可以。到目前为止,我有这个,但现在我被困住了。 CSV 文件的每一行都有一个名称,并且每个名称后都有一个逗号。任何帮助都会非常感谢。
这是我目前所拥有的:
string[] csvArray;
string line;
StreamReader reader;
OpenFileDialog openFileDialog = new OpenFileDialog();
//set filter for dialog control
const string FILTER = "CSV Files|*.csv|All Files|*.*";
openFileDialog.Filter = FILTER;
//if user opens file and clicks ok
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
//open input file
reader = File.OpenText(openFileDialog.FileName);
//while not end of stream
while (!reader.EndOfStream)
{
//read line from file
line = reader.ReadLine().ToLower();
//split values
csvArray = line.Split(',');
【问题讨论】:
标签: c# loops csv iteration counting