By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,382 Members | 2,058 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,382 IT Pros & Developers. It's quick & easy.

Does RichTextBox need "\r\n"? Is "\n" good enough?

P: n/a
In VB, you use ControlChars.CrLf (or better, ControlChars.NewLine).
In C/C++, we are used to using merely "\n" (or at least I am). It
appears "\n" is good enough for RichTextBoxes. Does it matter? I am
so used to typing "\n" that I don't think this habit will change
anyday soon.

Zytan

Mar 2 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On 2 Mar 2007 14:21:03 -0800, Zytan wrote:
In VB, you use ControlChars.CrLf (or better, ControlChars.NewLine).
In C/C++, we are used to using merely "\n" (or at least I am). It
appears "\n" is good enough for RichTextBoxes. Does it matter? I am
so used to typing "\n" that I don't think this habit will change
anyday soon.

Zytan
Probably not -- but its good practice to use Environment.NewLine
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 3 '07 #2

P: n/a
Probably not -- but its good practice to use Environment.NewLine

Will do, thanks.

Zytan

Mar 3 '07 #3

P: n/a
On Mar 2, 5:12 pm, "Rad [Visual C# MVP]" <nos...@nospam.comwrote:
Probably not -- but its good practice to use Environment.NewLine
--
Bits.Byteshttp://bytes.thinkersroom.com
Why exactly is this this the preferred practice?

Mar 3 '07 #4

P: n/a
sherifffruitfly <sh*************@gmail.comwrote:
Probably not -- but its good practice to use Environment.NewLine

Why exactly is this this the preferred practice?
Well indeed. From my point of view, Environment.NewLine should be used
whenever you're writing a text file to be viewed on the current system,
but lots of people seem to use it whenever they want a new line,
regardless of the context.

I know various Windows controls *require* \r\n, but different platforms
and UI libraries may well use a different new line to what the platform
usually uses for text files.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 3 '07 #5

P: n/a
On Sat, 3 Mar 2007 07:18:02 -0000, Jon Skeet [C# MVP] wrote:
sherifffruitfly <sh*************@gmail.comwrote:
>>Probably not -- but its good practice to use Environment.NewLine

Why exactly is this this the preferred practice?

Well indeed. From my point of view, Environment.NewLine should be used
whenever you're writing a text file to be viewed on the current system,
but lots of people seem to use it whenever they want a new line,
regardless of the context.

I know various Windows controls *require* \r\n, but different platforms
and UI libraries may well use a different new line to what the platform
usually uses for text files.
I would still think it's a good idea to use it, like in the scenario the OP
raised. I've not used Mono but I would not be surprised if the equivalent
control for the rich text box required a \n on its own, in which case using
\r\n might break the code if compiled for Mono

Personaly i do it that way not for issues of cross platform compatibility
but because I invariably forget one slash...
--
Bits.Bytes
http://bytes.thinkersroom.com
Mar 3 '07 #6

P: n/a
Rad [Visual C# MVP] <no****@nospam.comwrote:
I know various Windows controls *require* \r\n, but different platforms
and UI libraries may well use a different new line to what the platform
usually uses for text files.

I would still think it's a good idea to use it, like in the scenario the OP
raised. I've not used Mono but I would not be surprised if the equivalent
control for the rich text box required a \n on its own, in which case using
\r\n might break the code if compiled for Mono
On the other hand, Mono may well have emulated Windows Forms as closely
as possible, in which case using Environment.NewLine may well break
text areas etc (in that you wouldn't get a new line). I feel sorry for
the Mono team on issues like that...
Personaly i do it that way not for issues of cross platform compatibility
but because I invariably forget one slash...
That must be pretty obvious when it happens though.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Mar 3 '07 #7

P: n/a
sherifffruitfly wrote:
On Mar 2, 5:12 pm, "Rad [Visual C# MVP]" <nos...@nospam.comwrote:
>Probably not -- but its good practice to use Environment.NewLine

Why exactly is this this the preferred practice?
Network protocols : use \r\n no matter what platform it is.

Files : use Environment.NewLine and have the platform
translate that to \r\n or \n or something third.

Multi line controls in screens : read the documentation very
carefully - I would expect \r\n to be the correct way no
matter what platform.

Arne
Mar 4 '07 #8

P: n/a
I find this page very useful for reference:

http://en.wikipedia.org/wiki/Newline

Mar 5 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.