Problem in breaking a String

1

I have a string that is concatenated inside a loop , I wanted a new line with the concatenated values to be created for each loop .

Here is the code I'm using:

mensagem ="";

for (int i = 0; i < titulosReceber.Rows.Count; i++) 
    mensagem += "Titulos: " + (titulosReceber[i].TitId).ToString() +
    "FormaPagto: " + (titulosReceber[i].NomeMeioPagamento).ToString() +
    "Valor: " + (titulosReceber[i].Valor).ToString() + " Dt. Venc: " +
    (titulosReceber[i].dVenc)+"\n" ;

SalvarHistorico("Ação Faturar da Saida, gerado(s) o(s)"+ mensagem,
Historico.enumHistoricoTipo.SAI_Faturar, this.Saida[0].Id, IdOperador );
The string is concatenated, but does not break the line.

    
asked by anonymous 05.08.2015 / 15:19

3 answers

0
StringBuilder mensagem = new StringBuilder(); 

for (int i = 0; i < titulosReceber.Rows.Count; i++)
    mensagem.Append(string.Format("<br/><b>Titulos:</b> {0} <b>Forma Pagto: :</b>{1} <b>Valor :</b>{2} <b>Dt. Venc :</b>{3}", titulosReceber[i].TitId, titulosReceber[i].NomeMeioPagamento, titulosReceber[i].Valor, titulosReceber[i].dVenc.ToString("dd/MM/yyyy")).ToString());

    SalvarHistorico("Ação Faturar da Saida, gerado(s) o(s)"+ mensagem, Historico.enumHistoricoTipo.SAI_Faturar, this.Saida[0].Id, IdOperador );
    
07.08.2015 / 14:59
3

The line break is normally occurring through \n can not have this code.

Your problem is elsewhere. When you are going to display this generated string , you are not seeing the text break by how the engine that will render the presentation handles it. That is, when you print, \n is not visible as a line break. As you are using ASP.Net, you should be trying to show this in an HTML page, whose line break is represented by <br /> . So either you change this code to use this text as a break or when you mount the page it converts \n to <br /> .

    
05.08.2015 / 15:45
0

Where are you viewing this generated message? If it is in a HTML context, you can use mensagem.Replace(Environment.NewLine, "<br />") before displaying that it should work. Another option would be instead of putting \n put direct <br /> .

    
07.08.2015 / 14:07