views:

107

answers:

2

I have always used Replace(myString, vbCrLf, "<br/>") to show line breaks when outting something to a page from the database (retaining line breaks). I am now using a DetailsView that has a textarea as one of the fields and uses a LinqDataSource as its datasource. I want to allow users to type line breaks in the textarea and display them on a page (replaced with <br/>'s to show breaks in the HTML). Linq seems to be replacing the line breaks with something else that is now causing the Replace statement to not find the breaks, therefor not inserting the html <br/>. When loading the value from the database to a textarea the line breaks are still there though. I have tried replacing the following with <br> but none of it works.

vbCrLf
vbNewLine 
Environment.NewLine

...none of those work... what do I need to find/replace with <br> to show breaks?

A: 

Look at the string as a byte array, what values are the line breaks? There are only so many options here, 10, 13, both, none?

Rob Elliott
A: 

TextArea uses different newline characters depending on the browser:

  • Internet Explorer: \r\n
  • FireFox: \n

It has also been suggested that \r is used in some cases, although, I haven't come across those cases.

Carriage return is encoded as %0D and Line feed as %0A. So if your text is HTML encoded (as it should be), then you need to replace %0D and/or %0A [depending on your environment] with your <br />

Here is a full discussion on the topic http://www.highdots.com/forums/html/standard-newline-character-264611.html.

BenAlabaster
Thanks, HTMLEncoded using AntiXss its that gets replaced with <br/> and now works fine. Still not sure what what happening or what Linq changes it to though, vbCrLf has always worked in the past.
Ryan