tags:

views:

270

answers:

1

I'm working on displaying some text in a textarea that I've submitted via a form in my ASP.NET MVC app.

I want the line breaks to show when I'm displaying the text back.

Why does

Message.Replace(Environment.NewLine, "<br />")

not work, but

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

does?

Is the breakline character that the browser submits different than the windows Newline "\r\n" ?

+4  A: 

If you take a look at this stackoverflow answer, it explains which browsers use '\r\n' and which use '\n' in javascript. I'm not sure if that would apply to sending information to a server.

Either way, Environment.NewLine is the NewLine character for the environment where your web server is running. Your software running on the web server should not assume that a client's environment is the same as yours, so you should code, assuming that sometimes you will get Environment.NewLine, and sometimes you wont.

The common denominator is the '\n', so if you use your second code option, you should handle all of your cases.

mlsteeves