0

When I try and display text from an the InnerText from an XML element. I get something like this:

I need this spacing \r\n\r\n\r\second lot of spacing\r\n\r\nMore spacing\r\n\r\n

I know you can replace \r\n with <br> but is there no function that automatically takes the html for you and why does it use \r and \n? Many thanks.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208
mjroodt
  • 3,223
  • 5
  • 22
  • 35
  • 1
    possible duplicate of [Carriage return in XmlNode Innertext](http://stackoverflow.com/questions/1276243/carriage-return-in-xmlnode-innertext) – Jon Egerton Dec 05 '11 at 12:42

1 Answers1

3

You can use <pre> tag - it will show the text as-is like you see it in text editor:

For example:

<pre><%=MyText%></pre>

Better practice for ASP.NET is:

<pre id="myPlaceholder" runat="server"></pre>

Then assign its value from code behind:

myPlaceholder.InnerHtml = MyText;

As for your question "why does it use \r and \n" those are carriage return and line feed characters, aka newline characters - when you have such text:

line 1
line 2

Then code reading it will give: line1\nline2 or line1\r\nline2 depending on how it's stored exactly.

Shadow The GPT Wizard
  • 66,030
  • 26
  • 140
  • 208