PDA

View Full Version : مقایسه مقادیر دو فایل متنی



goodarziasl
دوشنبه 04 دی 1396, 18:31 عصر
سلام دوستان برنامه من قرار که از فایل تکس 1 خط به خط مقداری را برداره و توی فایل تکس دوم خط به خط جستجو کنه مشکل کدم اینجاست که از فایل تکس1 فقط خط اول را میخونه و سراغ خط دوم نمیره اینم کدم و ظاهرا فقط فایل تکس 2 را پیمایش میکنه راهنمایی کنید ممنون میشمTextWriter tw = new StreamWriter("d:\\file.txt"); try
{
FileStream str1 = new FileStream(txtPath.Text, FileMode.Open, FileAccess.ReadWrite);
StreamReader strreader1 = new StreamReader(str1);
FileStream str2 = new FileStream(txtPath2.Text, FileMode.Open, FileAccess.ReadWrite);
StreamReader strreader2 = new StreamReader(str2);
List<string> list = new List<string>();
string strf1 = "";
List<string> listf2 = new List<string>();
string strf2 = "";
while ((strf1 = strreader1.ReadLine()) != null)
{
list.Add(strf1);
try
{
while ((strf2 = strreader2.ReadLine()) != null)
{
listf2.Add(strf2);
if (strf1 == strf2)
{
MessageBox.Show(strf1 + "این شماره موجود است");
tw.WriteLine(strf1);
}
}
}


catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

goodarziasl
پنج شنبه 07 دی 1396, 15:17 عصر
foreach (string line in File.ReadLines(txtPath.Text)) {
foreach (string line1 in File.ReadLines(txtPath2.Text))
{
if (line == line1)
{
tw.WriteLine(line);
}
}

}
با این دستور درست شد