Newline environement.Only works in the first line

Asked

Viewed 32 times

0

Good afternoon. I am trying to generate a text file and it only works on the first line. From the second line, it gives you a space that you can’t solve.

foreach (DadosSQL dados in listaDados){
            sb.AppendFormat("{0, -18}{1, -10}{2, -37}{3, -15}{4, -25}{5, -10}{6, -15}{7, -18}{8, -20}{9, -11}{10, -22}{11, -19}{12, -21}{13, -21}",
                dados.REFERENCIA_ALIADO.ToString(), dados.COD_SKU_USUARIO, dados.NOM_SKU, dados.DESCRICAO, dados.NOM_MARCA_SORTIMENTO, dados.QTD_DISPONIVEL, dados.TIENDA, dados.PRECO, dados.PRECO_COM_DESCONTO,
            dados.DESCONTO, dados.INICIO_DESCONTO, dados.FIM_DESCONTO,  dados.CATEGORIA_1, Environment.NewLine);}   
        File.WriteAllText(@"c:\\Teste\\teste.txt", sb.ToString());

The output is in the attached image:

ErroNewLine

1 answer

1

The last format is adding spaces after the NewLine.

Change to that:

foreach (DadosSQL dados in listaDados)
{
  sb.AppendFormat("{0, -18}{1, -10}{2, -37}{3, -15}{4, -25}{5, -10}{6, -15}{7, -18}{8, -20}{9, -11}{10, -22}{11, -19}{12, -21}",dados.REFERENCIA_ALIADO.ToString(), dados.COD_SKU_USUARIO, dados.NOM_SKU, dados.DESCRICAO, dados.NOM_MARCA_SORTIMENTO, dados.QTD_DISPONIVEL, dados.TIENDA, dados.PRECO, dados.PRECO_COM_DESCONTO,dados.DESCONTO, dados.INICIO_DESCONTO, dados.FIM_DESCONTO,  dados.CATEGORIA_1);
  sb.Append(Environment.NewLine);
}   
File.WriteAllText(@"c:\\Teste\\teste.txt", sb.ToString());
  • Thank you very much.

Browser other questions tagged

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