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

  • Thread starter Thread starter Zytan
  • Start date Start date
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
 
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
 
Probably not -- but its good practice to use Environment.NewLine

Will do, thanks.

Zytan
 
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.
 
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...
 
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.
 
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
 
Back
Top