473,395 Members | 1,574 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

difference between carriage return(\r) and new line(\n)

hi

can any body explain what is the difference between carriage return (\r) or you can say Enter and New Line character(\n)..

both are treated as same..

in .net(c#) if you write a file using stream writer
like this.

StreamWriter writer=new StreamWriter("c:\\test.txt");
writer.Write("Hello\r\n------\r\nHow are You.");
writer.Close();

will print this..

Hello
------
How are You.

or if you use
StreamWriter writer=new StreamWriter("c:\\test.txt");
writer.Write("Hello\r------\rHow are You.");
writer.Close();

then the results will again be same as

Hello
------
How are You.

and finally if you use like this
StreamWriter writer=new StreamWriter("c:\\test.txt");
writer.Write("Hello\n------\nHow are You.");
writer.Close();

then again the result will be same as

Hello
------
How are You.

then what is the difference between \r and \n

please explain

regards
Vishal
Mar 8 '07 #1
1 16074
Hi,
this seems to be a hazy subject...
check out this link
http://channel9.msdn.com/ShowPost.aspx?PostID=169419

and esp this (second last post in the thread)

\r\n is the Windows line ending. (0xDA; CRLF)

\n is the UNIX line ending (0xA; LF)

Historically old-school "Classic" Macs used \r (0xD; CR) (but they called it \n to confuse people)

You'll see bare CRs only from Mac users who are using a Classic browser.

More at http://en.wikipedia.org/wiki/Newline
hi

can any body explain what is the difference between carriage return (\r) or you can say Enter and New Line character(\n)..

both are treated as same..

in .net(c#) if you write a file using stream writer
like this.

StreamWriter writer=new StreamWriter("c:\\test.txt");
writer.Write("Hello\r\n------\r\nHow are You.");
writer.Close();

will print this..

Hello
------
How are You.

or if you use
StreamWriter writer=new StreamWriter("c:\\test.txt");
writer.Write("Hello\r------\rHow are You.");
writer.Close();

then the results will again be same as

Hello
------
How are You.

and finally if you use like this
StreamWriter writer=new StreamWriter("c:\\test.txt");
writer.Write("Hello\n------\nHow are You.");
writer.Close();

then again the result will be same as

Hello
------
How are You.

then what is the difference between \r and \n

please explain

regards
Vishal
Mar 8 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Canes_Rock | last post by:
The information posted at: ...
4
by: Josh | last post by:
Hi, I'm using System.Data.DataSet.ReadXml to convert some xml from a webservice to a DataSet. The xml looks like: <?xml version="1.0"...
6
by: Laura D | last post by:
How can I identify a carriage return in C++? \r, \f, \0, \n, \t does not work. I have also tried !isprint(ch), iscntrl(ch), isspace(ch), etc....with no luck! I even poked around in the MSDN and...
2
by: Matt Mercer | last post by:
Hi all, I am having a frustration problem, and I have read about 25 newsgroup postings that do not have a satisfying answer :) The problem appears to be common where carriage returns are lost...
11
by: TheRain | last post by:
Hi, I am trying to append a carriage return to my string using the string builder class, but when I do this the string ends up containing "13". I tried this multiple ways like so ...
6
by: shajias | last post by:
Hi, I am having a xml code like this <name> I am having a carriage return here. Second line with carriage return. This is the last line. </name>
10
by: Chad | last post by:
Given: #include <stdio.h> #include <stdlib.h> #define MAXLINE 200 int main(void) { char buff;
1
by: nur123 | last post by:
Thanks in advance who will look at it. I have been encountering an issue which I can’t find a way out of it. What my pgm does: It (java codes) reads oracle table data and creates flat text...
11
by: evenlater | last post by:
My db allows the user to send email via CDO. The body of the email is determined in code. I have built an email form with To, CC and Subject lines and a large text box for the body of the message...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.