【发布时间】:2011-10-14 09:50:35
【问题描述】:
我有一个这样的 csv 文件:
george,
nick,
mary,
john,
micheal
用户可以制作他喜欢的文件。例如,他可以有 4 或 5 或 28 行。
我有另一个 csv 文件,我将它分配给一个名为 fileList1 的 ArrayList。这个文件是一个议程。
如果议程中的名称不在 csv 中,则会给出,然后打印一条消息。(这是我需要找到的)。关键是 csv 都可以是动态的。行数不规范。
我还有一张桌子,colB[]。此表包含将与列进行比较的文件列表。
问题是我无法选择数组列表中的特定列,因为它是一个数组列表。
ArrayList fileList1 = new ArrayList();
string stringforData;
private void button1_Click(object sender, EventArgs e)
{
// opens **BROWSE**
string filename = "";
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
filename = openFileDialog1.FileName;
textBox1.Text = filename;
// Read the file and display it line by line.
string line;
System.IO.StreamReader file1 = new System.IO.StreamReader(textBox1.Text); //reads the path from textbox
stringforData = file1.ReadLine();
while ((line = file1.ReadLine()) != null)
{
// bazei stoixeia mesa ston pinaka
fileList1.Add(line.Split(';'));//split the file and assign it in //the fileList1
}
file1.Close();
}
}
private void button3_Click(object sender, EventArgs e)
{
this.textBox2.Clear();
string[] colB = new string[];
for (int j = 0; j < colB.Length; j++)
{
if (Path.GetExtension(colB[j]) == ".csv")
{
string path = Path.GetDirectoryName(textBox1.Text);
string g = Path.Combine(path, colB[j]);
textBox2.Text += "the path is " + g + " " + Environment.NewLine;
System.IO.StreamReader gi = new System.IO.StreamReader(g);
string itemss;
ArrayList ArrayForLists=new ArrayList();
while ((itemss = gi.ReadLine()) != null)
{
ArrayForLists.AddRange(itemss.Split(';'));// assign to the arraylist the list that we are searching
}
}
【问题讨论】:
标签: c# arrays list arraylist compare