Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   \r vs \n\r and related issues (http://www.velocityreviews.com/forums/t133935-r-vs-n-r-and-related-issues.html)

Aaron Fude 05-30-2004 04:18 AM

\r vs \n\r and related issues
 
Hi,

I'm a little confused by the \r \n\r differences between operating systems.
For example, does the output of println() depend on the operating system?
Also, what is a reliable way to use a StringTokenizer to break up input into
lines - what do you use as a delimiter?

Thanks,

Aaron



Sudsy 05-30-2004 04:29 AM

Re: \r vs \n\r and related issues
 
Aaron Fude wrote:
> Hi,
>
> I'm a little confused by the \r \n\r differences between operating systems.
> For example, does the output of println() depend on the operating system?
> Also, what is a reliable way to use a StringTokenizer to break up input into
> lines - what do you use as a delimiter?


From the javadocs (always a good place to start) for PrintWriter:

"The println() methods use the platform's own notion of line separator
rather than the newline character."

As to parsing input, that's why we have BufferedReader. From the
javadocs (again) we find the following text in the readLine method
description:

"A line is considered to be terminated by any one of a line feed ('\n'),
a carriage return ('\r'), or a carriage return followed immediately by
a linefeed."

IOW, you don't have to worry about it! I can even FTP a file from M$
to a *NIX box and read it with no problems.


Frank 05-30-2004 04:46 AM

Re: \r vs \n\r and related issues
 
> I'm a little confused by the \r \n\r differences between operating
> systems.
> For example, does the output of println() depend on the operating system?


The answer here is technically yes. println() calls will write the current
platform's default line seperator to the output. Conceptually, this should
be relatively transparant to you though, as, regardless of the platform,
it will generate a new line. This does get a bit problematic though, when
the output is not necessarily displayed on the same machine that is
generating it :/

> Also, what is a reliable way to use a StringTokenizer to break up input
> into
> lines - what do you use as a delimiter?


"\r\n" should work just fine as a delim for StringTokenizer. That way,
either single char will mark an EOL, and a doubled instance should get
ignored.

Hope this helps!

Frank

Roedy Green 05-30-2004 05:21 AM

Re: \r vs \n\r and related issues
 
On Sun, 30 May 2004 04:18:37 GMT, "Aaron Fude" <aaronfude@yahoo.com>
wrote or quoted :

>I'm a little confused by the \r \n\r differences between operating systems.
>For example, does the output of println() depend on the operating system?


see http://mindprod.com/jgloss/file.html#PLATFORMSPECIFIC
--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.

Tony Morris 05-30-2004 05:28 AM

Re: \r vs \n\r and related issues
 


"Aaron Fude" <aaronfude@yahoo.com> wrote in message
news:xgduc.16905$4A6.8274@attbi_s52...
> Hi,
>
> I'm a little confused by the \r \n\r differences between operating

systems.
> For example, does the output of println() depend on the operating system?
> Also, what is a reliable way to use a StringTokenizer to break up input

into
> lines - what do you use as a delimiter?
>
> Thanks,
>
> Aaron
>


http://www.xdweb.net/~dibblego/java/...swers.html#q44

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
(2003 VTR1000F)



Tony Morris 06-03-2004 10:42 AM

Re: \r vs \n\r and related issues
 
> I was wonderring at the time why
> you do not mention ..
> System.getProperty("line.separator")
> .. in that entry.


I'm not sure if either a) I do not understand your question or b) you
overlooked that I did in fact mention the "line.separator" system property:
<quote>
You can obtain the EOL terminator by accessing the System property called
"line.separator".
</quote>
Am I missing something in your question?

The sharp eye will have noticed that I quoted the hexadecimal values for \r
and \n incorrectly - this is pending on my "to do list" to fix.

--
Tony Morris
(BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
Software Engineer
IBM Australia - Tivoli Security Software
Home : +61 7 5502 7987
Work : +61 7 5552 4076
Mobile : 0408 711 099
(2003 VTR1000F)




Andrew Thompson 06-03-2004 02:17 PM

Re: \r vs \n\r and related issues
 
On Thu, 03 Jun 2004 10:42:25 GMT, Tony Morris wrote:

> Am I missing something in your question?


No. I was missing something in your answer. ;-)

> The sharp eye will have noticed that I quoted the hexadecimal values for \r
> and \n incorrectly - this is pending on my "to do list" to fix.


This 'sharp eye' did not even
pick up the reference to
System.getProperty("line.separator")
...and your talkin' hex??

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Peter Kirk 06-04-2004 08:43 AM

Re: \r vs \n\r and related issues
 
"Tony Morris" <not@telling.you> skrev i en meddelelse
news:Rheuc.17548$L.12673@news-server.bigpond.net.au...
>
> "Aaron Fude" <aaronfude@yahoo.com> wrote in message
> news:xgduc.16905$4A6.8274@attbi_s52...
> > Hi,
> > I'm a little confused by the \r \n\r differences between operating

> systems.
>
> http://www.xdweb.net/~dibblego/java/...swers.html#q44


This webpage says this:

"\r\n" (0x00D0 0x00A0);

Are these values ASCII, and if so are they correct?

Peter


Andrew Thompson 06-04-2004 09:39 AM

Re: \r vs \n\r and related issues
 
On 4 Jun 2004 10:43:58 +0200, Peter Kirk wrote:
> "Tony Morris" <not@telling.you> skrev i en meddelelse
> news:Rheuc.17548$L.12673@news-server.bigpond.net.au...

...
>> http://www.xdweb.net/~dibblego/java/...swers.html#q44

....
> "\r\n" (0x00D0 0x00A0);
>
> Are these values ASCII, and if so are they correct?


'..sharp eye'
<http://groups.google.com/groups?th=7ef41428544ff90c#link7>

--
Andrew Thompson
http://www.PhySci.org/ Open-source software suite
http://www.PhySci.org/codes/ Web & IT Help
http://www.1point1C.org/ Science & Technology

Roedy Green 06-04-2004 12:35 PM

Re: \r vs \n\r and related issues
 
On Fri, 04 Jun 2004 09:39:42 GMT, Andrew Thompson
<SeeMySites@www.invalid> wrote or quoted :

>> "\r\n" (0x00D0 0x00A0);
>>
>> Are these values ASCII, and if so are they correct?

no. A0 is often used an non-breaking space. that should read 0x0a.

--
Canadian Mind Products, Roedy Green.
Coaching, problem solving, economical contract programming.
See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.


All times are GMT. The time now is 04:19 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.