Two new lines in string

Santosh 21 Reputation points
2021-05-27T12:44:48.73+00:00

I have the following code snippet. I want to add two new lines after variable "automatedComment ". I tried the following way. But its taking only one line after the URL in automatedComment. Please let me know how can I add two lines after URL

        string automatedComment = "<b>Note:</b>" + " Your comment will not be read." +
                                  "For more details, " + "please refer the wiki <URL>";
        string description = automatedComment + Environment.NewLine + "" +
                              "TEST MESSAGE" + Environment.NewLine + "" +
                             Environment.NewLine +
                             Environment.NewLine + "Logs path: " + 
                             Environment.NewLine + 
                             Environment.NewLine + Environment.NewLine + "<b>==== List of Similar " +  " Test Projects With Same issue ====</b>" +
                             Environment.NewLine ;

        description = description.Trim().Trim(Environment.NewLine.ToCharArray());

        description = "<p>" +  + description.Replace(Environment.NewLine, "</p><p>") + "</p>";

Kindly waiting for your inputs.

Thanks,
Santosh

Developer technologies C#
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Viorel 122.5K Reputation points
    2021-05-27T13:12:02.33+00:00

    Try using one or more "<br/>" instead of Environment.NewLine. If you cannot change the first part, then use something like 'description = description.Replace(Environment.NewLine, "<br/>").

    0 comments No comments

  2. Timon Yang-MSFT 9,606 Reputation points
    2021-05-28T02:13:18.757+00:00

    This should be an html problem.

    It is best not to use <p></p> to create a new line, even if you need to use it for some reason, it should be <p>&nbsp;</p>.

    However, this method is not recommended. It is better to use <br/> according to Viorel-1's suggestion.


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.