我的标准很少,例如只选择今天的记录,而且如果记录包含字母“CA”,现在我想在这两个之前添加一个标准,在其中我跳过任何基于 ID 号重复的记录。
这是我的代码
private void btn_convert_Click(object sender, EventArgs e)
{
if ((textBox1.Text == "" )&& (textBox2.Text == ""))
{
MessageBox.Show("Please specify input and output");
}
StringBuilder csvFile = new StringBuilder();
string temp = "";
// string[] file = File.ReadAllLines(@"C:\Users\Program\Desktop\test.txt");
string[] file = File.ReadAllLines(textBox1.Text);
foreach (string line in file)
{
//here I want to add an if condition where only write the unique records based on ID number
if ((line.Contains(DateTime.Now.ToString("MM/dd/yyyy"))) && (line.Contains("\tAU\t"))){
if (line.Contains("\t"))
{
temp = line.Replace("\t", ",");
csvFile.Append(temp + "\r\n");
continue;
}
csvFile.Append(line + "\r\n");
}
}
//File.WriteAllText(@"C:\Users\Program\Desktop\test.csv", csvFile.ToString());
File.WriteAllText((textBox2.Text + "\\test.csv"), csvFile.ToString());
MessageBox.Show("CSV file successfully created at the following location :\n" + textBox2.Text);
}