我有幾個標準,如只挑選記錄到一天,也如果一條記錄包含字母'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);
}
不知道爲什麼人們正在縮小過於本地化,您可以忽略代碼和完全的輸入/輸出和問題仍然是交代,並適用於其他人同樣的情況(這是一種常見的情況,所以會有其他人)。 – Servy