Text with line break

Asked

Viewed 428 times

3

I pass some product instructions for an external charge service (website). On the screen of this site, the past messages are in the "description" field, inside an element h3, which seems to have 25 spaces with flexible height.

I pass like this:

var descricao = "Codigo: " + codigoProduto + Environment.NewLine + "Nome: " + 
nome + Environment.NewLine;

try
        {
            paymentRequest.Items.Add(
             new Item(
                "BASIC " + CodID,
                 descricao,
                 1,
                 valor
             )
         );

On the screen everything appears together in the same line of that field description.

However, the intention is to have an info on each line, for example:

Código: 1234
Nome: Daniel

This way it works but appears the br on the screen.

descricao = $"Codigo: {CodID} <br/> Nome: {nome}";

Source code of the page receiving the data:

      <td>
        <h3 title="Codigo: 1983 br / Nome: Daniel">Codigo: 1983 br 
         / Nome: Daniel</h3>
            Quantidade: 1<br />
            Valor do item: R$ 6,00
        </td>
  • 1

    The question tag already helps you identify which language you’re talking about. You don’t need to put it in the title.

2 answers

3


Another solution:

string retorno = $"<h3>Codigo: {codigoProduto} <br> Nome: {nome} <br> Valor:  {valor} </h3>";
  • 1

    For the case in question the answer above was the closest.

2

You can do it like this:

var NewLineHTML = "<br>" + Environment.NewLine;

var res = $"Codigo: {codigoProduto}" + NewLineHTML +
          $"Nome: {nome}" + NewLineHTML +
          $"Valor: {valor}" ;

what would look like in html, inside the tag h3 preexisting:

<h3>
Codigo: 789<br>
Nome: CHURRASCO<br>
Valor: 12,34
</h3>

Rendered:
exemplo


Patch (Patch): From what I’ve seen the system is taking out the < and > and so it appears br ...
Maybe you can try to hack it by doing this:

change to:

var NewLineHTML = "_br_" + Environment.NewLine;

and on the page add this script

<script>
    document.body.innerHTML = document.body.innerHTML.replace(/_br_/g, '<br>');
</script>
  • the site did not render as. It was all together.

  • Even with the <br> it did not render? Check the HTML generated in the browser, maybe the site is removing the tags <br>

  • br appears even on the screen.

  • 1

    Can you add to the question this excerpt that is being generated? It would then be some CSS that’s influencing this?

  • Ah, yes, so he’s escaping the < and > or by removing them?

  • 1

    Add site print to question;

  • No way. Don’t break the line ....

Show 2 more comments

Browser other questions tagged

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