Hi im trying to make a console application which reads 2 text files deletes the repeats words in the text file and writes it to one. Im trying to do 2 while loops inside each other the one reading a line at a time on the one file and the other reading all of the other file and seeing if the one is contained into the other.
1. it will only loop through once
2. when i change the if (strText2.Contains(strText1) == false) to if (strText2.Contains(strText1)) it writes the word that it containes so why wont it write the word that it doesnt contain??
Code -
Code:if (strMenu == "1")//Start conversion { Console.WriteLine("Please enter the file path of the 1st text file"); strFile1 = Console.ReadLine(); //set string to inputted file path StreamReader sr = new StreamReader(strFile1); // new streamreader Console.WriteLine("Please enter the file path for the second file"); strFile2 = Console.ReadLine(); StreamReader sr2 = new StreamReader(strFile2); Console.WriteLine("Please enter the file path where you want the new text file to be saved"); strSaveFilePath = Console.ReadLine(); StreamWriter sw = new StreamWriter(strSaveFilePath); sw.AutoFlush = true; while (sr.ReadLine() != null) { strText1 = sr.ReadLine(); while (sr2.ReadLine() != null) { strText2 = sr2.ReadToEnd(); if (strText2.Contains(strText1) == false) { Console.WriteLine(strText1); break; } } }




Reply With Quote