Environment.NewLine sometimes returns \n Linefeed instead of \r\n Carriage Return, Line Feed
I'm displaying an address to a user on a ASP.Net page using a label. The new lines are converted from
Environment.NewLine
to
<br />
If a user edits the address, the address is displayed in a text area and the
<br />
is replaced with
Environment.NewLine
Sometimes the address saved to the database only has the line feed. Given how often this happens, it looks like it could be happening for Linux or OSX users.
Does Environment.NewLine return the new line value of th开发者_开发百科e client's browser or of the server, or could it something else?
No, Environment.NewLine
returns whatever's on your server (because that's where it's running). It's entirely possible that a browser running on Unix will submit data with just "\n" instead of "\r\n" as the line-break. It sounds like you should be normalizing the data before saving it in the database. Then you know you can perform the replacement to <br />
safely for display purposes.
(I'm assuming your server is running on Windows, and that that's where all your code is - i.e. there's no Silverlight etc involved.)
精彩评论