How to convert line breaks in input form in ASP.NET?

How do you usually convert line breaks into a text field of a form or input = text element into html line breaks?

thanks

Edit: is it always \ r \ n with all browsers?

+3
source share
6 answers

Or in C #:

myString.Replace("\r\n", "<br />");

If you are concerned that they are different on different platforms, you can also:

myString.Replace("\r\n", "<br />");
myString.Replace("\n", "<br />");
myString.Replace("\r", "<br />");
+6
source

Is it always \ r \ n with all browsers?

It is processed on the server; it has nothing to do with the browser. However, I would suggest using:

System.Environment.NewLine  
+4
source
Replace(vbcrlf, "<br />")
+2
Regex.Replace(urString, "\r?\n", "< br/>");
+1

:

MyString.Replace(Chr(10), "<br/>")
0

, , , , .

MyString.Replace("\\r\\n", "<br />")

MyString.Replace("\\r\\n", Environment.NewLine)
-1

All Articles