How to get HTML line breaks from long text fields

I am not sure this has ever come up (at least I can’t find anything). I have no problems generating neat HTML formatted emails based on things happening in Epicor. However, I came across one thing I can’t figure out today.

When I take a long description that contains line breaks/carriage returns, they don’t carry over into the HTML formatted email. I have tried doing a replace in the body string… but maybe I’m not sure how to identify what I am replacing properly to get the HTML line break.

Anyone have any ideas?

Are you replacing the Char(10) or Char(13) with

<br> 
or
<br /> 
2 Likes

i tried:

.Replace(Environment.NewLine, "\r\n")
.Replace(Environment.NewLine, "<br>")
.Replace("\r\n", "<br>")
.Replace("\r\n", Environment.NewLine)
.Replace(Char(13), "\r\n")

It doesn’t recognize the Char in the C# editor. What am I missing? If it helps, I am trying to take content from PartRev.RevDescription that has line breaks in the text and put it on an email and maintain the line breaks.

Are you sure there is both a “\r” and “\n”? Try each on their own with the break element.

also, in C# it’s

Convert.ToChar(i)

where i is 10, 13, or whatever.

3 Likes

Usually I try to make sure I’m only looking at one possibility so I would do 2 stage replace:

\r\n with \n
\n with <br />
2 Likes

That’s it. It replaced with \r but not \n. Excellent!

1 Like