I am having trouble attempting to find words in a text file in C#.
I want to find the word that is input into the console then display the entire line that the word
As mantioned by @Rinecamo, try this code:
string toSearch = Console.ReadLine().Trim();
In this codeline, you'll be able to read user input and store it in a line, then iterate for each line:
foreach (string line in System.IO.File.ReadAllLines(FILEPATH))
{
if(line.Contains(toSearch))
Console.WriteLine(line);
}
Replace FILEPATH
with the absolute or relative path, e.g. ".\file2Read.txt".