namespace WordSearch { class Program { public static void Main() { // Start To Show the file FileStream inFile1 = new FileStream(@"D:\Tricube_Task\Code_Fun\Hello.txt", FileMode.Open, FileAccess.Read); using (StreamReader file = new StreamReader(inFile1)) { int counter = 0; string ln; while ((ln = file.ReadLine()) != null) { Console.WriteLine(ln); counter++; } //file.Close(); Console.WriteLine($"File has {counter} lines."); } // End To Show the File // Start To show the word in the file //the path of the file FileStream inFile = new FileStream(@"D:\Tricube_Task\Code_Fun\Hello.txt", FileMode.Open, FileAccess.Read); StreamReader reader = new StreamReader(inFile); string record; string input; Console.Write("Enter The word:");// User Input input = Console.ReadLine(); try { //the program reads the record and displays it on the screen record = reader.ReadLine(); while (record != null) { if (record.Contains(input)) { Console.WriteLine(record); } record = reader.ReadLine(); } } finally { //after the record is done being read, the progam closes reader.Close(); inFile.Close(); } // End Show the word in the file // Exit from application Console.Write("Press 'Q' to Quit from Program.. "); while (Console.ReadKey().Key != ConsoleKey.Q) { } Console.ReadLine(); // Exit from application } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)