I need to extract a particular part of a Txt from the fetch of a value.

Example: When I search for "147" the program locates in my Txt.

enter image description here

My Txt

enter image description here

From this search I want to save the above data until the CNPJ line that is in the Txt, each row in a variable. So he needs to record the 9 lines.

My code to record

private void btnSalvar_Click_1(object sender, EventArgs e)

    StreamWriter sw = File.AppendText("c:\\form\\registro " + DateTime.Now.ToString("dd"+"-"+"MM"+"-"+"yyyy") + ".txt");

    string dia = DateTime.Now.Day.ToString();
    string mes = DateTime.Now.Month.ToString();
    string ano = DateTime.Now.Year.ToString();
    string hora = DateTime.Now.ToString("H:mm");

    String esp = "--------------------------------------------------------\r\n";

    tpv = "N° TP:  " + txbTp.Text + "\r\n";

    sw.WriteLine("==> " + dia + "/" + mes + "/" + ano + " - " + hora);
    sw.WriteLine("Numero do portal:" + portalweb);


My code to search

private void button1_Click_1(object sender, EventArgs e)
    if (File.Exists("c:\\form\\registro " + DateTime.Now.ToString("dd" + "-" + "MM" + "-" + "yyyy") + ".txt"))
        String varPalavra = txbTp.Text;

        StreamReader re = File.OpenText(@"c:\\form\\registro " + DateTime.Now.ToString("dd" + "-" + "MM" + "-" + "yyyy") + ".txt");
        string input = re.ReadToEnd();

        if (input.IndexOf(varPalavra) > -1)
            MessageBox.Show("Existe a palavra '" + varPalavra + "' no arquivo txt");
            MessageBox.Show("Não existe a palavra '" + varPalavra + "' no arquivo txt");

        MessageBox.Show("O arquivo registro atual não existe!");

closed as off-topic by c32hedge, NarendraC, Ray Oei, Nitin Rastogi, Bharat Mane Jan 17 at 7:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – c32hedge, NarendraC, Ray Oei, Nitin Rastogi, Bharat Mane
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    What is the actual problem? Are you not finding the data you're looking for? What are you trying to test in this case? We are a software quality and testing group - for a pure programming problem you are likely to get a better result from stackoverflow. – Kate Paulk Jan 11 at 20:32
  • I find the field I need, but I can not extract the information I need from the archi. I wanted to know how to go about extracting this txt information based on a search. I would like to know if it is necessary to change how you write the information or read if it is necessary to use a vector to write and read the txt file. – Ronison Matos Jan 11 at 22:44

Browse other questions tagged or ask your own question.