differences between \r\n and \n
I eventually had to learn this, I knew it! , now that I am making a font thing for my game I finally figure out that I have to learn the difference between \r\n and \n
\r\n is a carriage return followed by a newline. \n is just the newline. Since the days of teletype machines is mostly gone, \r\n is usually converted to just \n and handled that way.
Some operating systems use the value 0x0a ('\n') to mark the end of a line. Some use the value 0x0d ('\r') to mark the end of a line. Some use the sequence 0x0d,0x0a ("\r\n").
The C and C++ libraries automatically convert to the proper marker when a '\n' is written to file or stream in text mode, and convert from the end-of-line marker to '\n' when reading from a file or stream in text mode.
The C and C++ libraries automatically convert to the proper marker when a '\n' is written to file or stream in text mode, and convert from the end-of-line marker to '\n' when reading from a file or stream in text mode.
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.
Quote:Original post by Skeleton_V@T
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.
That's not really true; as long as you use the correct text mode flags on file output, the OS should convert \n to the correct line terminator for the operating system.
Quote:Original post by Skeleton_V@T
For maximal compatibility you might want to use "\r\n" whenever possible. Some programs such as notepad don't interpret "\n" as "\r\n" hence don't display the text correctly.
On the other hand, some programs don't expect the '\r' before \n, and so, they end up printing something like ^M at the end of every line.
I'm not aware of such a program, anyway, I rely on the API to do the convertions, thanks for correcting this.
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.
Quote:Original post by njpaul
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.
.Net has Environment.NewLine to solve such problems
Quote:Original post by Anonymous PosterQuote:Original post by njpaul
I know when I did some .NET programming last week and used the text edit box I had to use \r\n to get a new line. Just using \n resulted in garbage.
.Net has Environment.NewLine to solve such problems
OT: But it really _should_ be transparent in WinForms controls, too sad it isn't. Getting/setting text for a control should do the same thing as opening a file in text-mode: writing \n should be converted to \r\n and reading \r\n should be converted to \n.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement