Difference between \015 & \012 and \r & \n
Solution 1
\015
is an octal literal, which C# does not support.
C# parses it as \0
(character code zero) followed by the two characters 15
Solution 2
There is no difference between \r\n
and \015\012
.
In C(++), the \0XX
escape sequence denotes a literal octal representation of a char. If you print these values as numbers, you should see that \r
equates to 13
and \n
equates to 10
.
Octal is base 8, and when converted to base 10, 015
equates to 13
, and 012
equates to 10
. I hope that clears things up.
Jon
Updated on December 02, 2020Comments
-
Jon over 3 years
I have an old C++ program that is writing files and FTPing them to a IBM mainframe.
This program is being converted to C#.
Things seems OK in transferring but the mainframe viewer is not displaying the file properly.
What is the difference between
\015
&\012
and\r
&\n
? C++ is using the numbers and C# is using\r\n
.Could this be why things don't appear properly?
The files are getting transferred as ASCII so unsure why it appears like garbage!
-
Bo Persson about 13 yearsThere is a difference on the mainframe end though, which might explain the original source using explicit numbers.
-
Jon about 13 yearsWould the IBM Mainframe not interpret \r \n hence the garbarge loooking file?
-
Kaslai about 13 yearsYes, I suppose that's somewhat logical. Modern day standards are well, modern, so it would stand to reason that an old application wasn't privy to such things as \r\n (cross-compiling, maybe?), and thus had to use literals.