'How can I read a text file with StreamReader selectively?
I am trying to use a loop to collect all the elements in a text file and select out of those elements specific ones to display.
{
string lines = File.ReadLines(path).Where(line => line.StartsWith("Name: ")).ToString();
foreach (string line in lines)
{
MessageList.Items.Add(lines);
}
}
The idea with this code is for the file stream to parse the entire document and only select the lines that start with Name:, ignoring all other ones so I can add the
I can't seem to get around the syntax error within the condition of the foreach loop. It says I'm trying to convert between char and string and the compiler is confused by my request. I've tried doing this with and without invoking ToString(), I've also tried it by declaring lines as a var instead of a string. I tried to do this without the lambda expression
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
