Read text file with Linq in C # and apply filters
The following method allows you to read a text file, apply filters and store it in a string list.
References
using System.Linq;
using System.IO;
File «test.txt«
VICTOR COMPUTER
SAP CONSULTANT
CLAUDIO COMPUTER
FELIPE
Code
string path = "C:\\test.txt"; List lineas = (from l in File.ReadAllLines(path) where l.Contains("COMPUTER") select l).ToList(); //Test with filters
The result will be a list with 2 elements:
VICTOR COMPUTER
CLAUDIO COMPUTER
We hope it is of your use, we remain attentive to your comments …
regards