Compare and print comma separated data

Asked

Viewed 52 times

0

I am unable to compare with the data in the notepad. This data is inserted online and separated by; In short, enter

value;description;day;month;year

if (dia == "" || mes == "" || ano == "") 
{
  ERRO erro = new ERRO();
  erro.Show();
} else {
  using(StreamReader lerentrada = new StreamReader(@ "escreveentrada.txt"))
  {


    string[] leitor = lerentrada.ReadLine().Split(';');
    if (leitor[0] != null) 
    {
      while ((leitor[0] = lerentrada.ReadLine()) != null) 
      {
        if (leitor[2] == TDia.Text) 
        {
          if (leitor[3] == Tmes.Text)
          {
            if (leitor[4] == Tano.Text) 
            {
              TRelatorio.AppendText($ "{leitor}{Environment.NewLine}");
            }
          }
        }
      }
    } else {


    }
  }
}
  • 2

    Any particular problem? Is the file too large? The computer has too much memory restriction?

  • In fact, I don’t think I can read the data correctly. Because the Textbox data until it goes right in, you know? But when it comes to comparing, it doesn’t compare.

  • You’re reading it right, I can assure you frmework that does it and it does not err, the problem is in something after that.

  • I get it, I just wonder if I’m comparing it correctly then?

  • 2

    That’s the problem with the question, only you know.

  • Complicated. But I entered the data this way as I said Value;Description;dia;mes;ano

Show 1 more comment

2 answers

0

The problem is the way you’re reading the information.

I think you’ll get there:

if (dia == "" || mes == "" || ano == "") 
{
    ERRO erro = new ERRO();
    erro.Show();
} 
else 
{
    using(StreamReader lerentrada = new StreamReader(@ "escreveentrada.txt"))
    {
        string linha = string.Empty;

        while ((linha = lerentrada.ReadLine()) != null) 
        {
            string[] leitor = linha.Split(';');

            if(leitor[0].Length == 0)
                continue;

            if (leitor[2] == TDia.Text && leitor[3] == Tmes.Text && leitor[4] == Tano.Text)
                TRelatorio.AppendText($"{leitor}{Environment.NewLine}");
        }
    }
}

0

I believe the problem is in your while.

In the stretch:

while ((leitor[0] = lerentrada.ReadLine()) != null) 

You are placing all the reading of the file line in the first position of the vector (the position 0), but soon after you compare the positions 1,2 and 3 of the vector. As it stands, only the position [0] of the reader vector is being updated.

Change the code as below and it should work.

while ((leitor[] = lerentrada.ReadLine().Split(',')) != null)

Browser other questions tagged

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