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
CLAUDIO COMPUTER
FELIPE
SAP CONSULTANT

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

También te podría gustar...

Deja una respuesta

Tu dirección de correo electrónico no será publicada.