Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

linebreaks

 
Csaba Kassitzky
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone!

Someone mentioned \n and \r are the linebreaks.
Can "\n\r" be used both? Does this count as one linebreak?

Thanks!
 
C Broussard
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i usually just do "\r\n"

not sure if switching works it.. you can write a quick static main and test it though...

public class test{

public static void main(String[] args){
System.out.print(" 1) this is a \r\n test ");
System.out.print(" 2) this is a \n\r test ");
System.out.print(" 3) this is a \n test ");
System.out.print(" 4) this is a \r test ");

}
}

just compile and run.


www.binaryfrost.com
 
Csaba Kassitzky
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
\r makes the whole line dissappear
Anyways, if i'm reading characters in, \r\n are 2 charaters right?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
See this thread...

http://www.coderanch.com/t/399847/java/java/when-why-we-FF-CR
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When reading in a text file, it's more common to read it in one line at a time, versus one character at a time. For the former, BufferedReader has the method readLine:

Read a line of text. 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.

The string readLine returns does not include any terminator.

But if you are reading one character at a time, "\r\n" is two chars.
 
Tony Morris
Ranch Hand
Posts: 1608
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic