Compare and print comma-separated data

0

I can not seem to make the comparison with the data in the notebook. This data is entered all inline 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 {


    }
  }
}
    
asked by anonymous 17.08.2018 / 19:30

2 answers

0

I think the problem is in your while.

In the excerpt:

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

You are placing all the line reading of the file in the first position of the vector (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)
    
27.08.2018 / 20:59
0

The problem is how you read the information.

I think that way you can 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}");
        }
    }
}
    
31.08.2018 / 15:00