Read from a pre line defined in txt

Asked

Viewed 85 times

2

I am making a txt file to save some information of a root user (user,password,name,Cpf,email) in order, and I would like to know how to read only the line that I would like, Cpf or email or user.

inserir a descrição da imagem aqui

  • The CPF and Email line is always the same?

  • yes, it’s always the same

1 answer

3


You can do it this way

string cpf = File.ReadAllLines(@"caminho\arquivo.txt")[3];

in case is passed the line index(3 because the indicies start at 0)

Another alternative is to put all lines in a list of string and then take the desired element

List<string> linhas = File.ReadAllLines(@"caminho\arquivo.txt").ToList();

string cpf = linhas.ElementAt(3);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.