我有三个文本文件:file1 file2和file3,它们都包含电子邮件。 file1应该有所有的电子邮件在那里,file2的所有电子邮件是AM,并且文件3有来自nz的电子邮件(这并不重要,但我认为这将有助于给出一点上下文。)比较文本文件的字符串
我正在写一个c#中的控制台应用程序,它将查看这三个文件,如果有一个不是1的电子邮件,它将写入一个主文件,该文件将说明需要添加什么内容。
例如,假设我有电子邮件[email protected]
。如果它在file1中找到但不在file2中,则主文件的输出需要为"this email needs to be added to file2: [email protected]"
。现在,如果它被颠倒了,并且电子邮件被发现在file2中但不在file1中,那么输出应该是"this email needs to be added to file1: [email protected]"
作为我的代码的一部分,我正在寻找的答案需要在某种foreach循环中进行,如果陈述,但是我有点失去了我需要的东西。如果有人可以请帮助我弄清楚我必须在我的陈述中使用什么,我将非常感激。如果有人对此有任何疑问,请随时询问!
//Making a list for file1
List<string> listFullPack = new List<string>();
string line;
StreamReader sr = new StreamReader("file1");
while ((line = sr.ReadLine()) != null)
{
listFile1.Add(line);
}
sr.Close();
//Making a list for file2
List<string> listDen1 = new List<string>();
string line1;
StreamReader sr1 = new StreamReader("file2");
while ((line1 = sr1.ReadLine()) != null)
{
listFile2.Add(line1);
}
sr1.Close();
//Making a list for file3
List<string> listDen2 = new List<string>();
string line2;
StreamReader sr2 = new StreamReader("file3");
while ((line2 = sr2.ReadLine()) != null)
{
listFile3.Add(line2);
}
sr2.Close();
//This will double check that emails are in
foreach (string element in listFullPack)
{
System.Console.WriteLine(element);
Debug.WriteLine(element);
if (element == "[email protected]")
{
Debugger.Break();
}
}
//this will compare the file1 list to the file2 list
var firstNotSecond = listFile1.Except(listFile2).ToList();
var secondNotFirst = listFile2.Except(listFile1).ToList();
//this will compare the file2 list to the file3 list
var firstNotThird = listFile1.Except(listFile3).ToList();
var thirdNotFirst = listFile3.Except(listFile1).ToList();
//this will compare the file2 list to the file3 list
var secondNotThird = listFile2.Except(listFile3).ToList();
var thirdNotSecond = listFile3.Except(listFile2).ToList();
foreach (string element in listFile1) // This is where I am lost
{
if (!)
{
}
}
在每个文件的电子邮件地址排序? – juharr
请注意,示例电子邮件通常类似于“email @ example.com”或“example @ email.com”或“burn.burnitall @ aol.com”。 –
@QPaysTaxes我知道,我只是想做一些不同的事情。它的星期五haha –