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

Z

Zytan

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
 
R

Rad [Visual C# MVP]

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
 
Z

Zytan

Probably not -- but its good practice to use Environment.NewLine

Will do, thanks.

Zytan
 
J

Jon Skeet [C# MVP]

sherifffruitfly said:
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.
 
R

Rad [Visual C# MVP]

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...
 
J

Jon Skeet [C# MVP]

Rad said:
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.
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

sherifffruitfly said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top