Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Duplicating eol characters in simple script?

 
Bob Smitheeeee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I need some help with the following script. It inserts 2 newlines instead of 1 as I think it should:



Outputs:



This is a windows machine. Any ideas? Thanks!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to use Groovy, then go all out man!

 
Bob Smitheeeee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gregg Bolinger wrote:If you're going to use Groovy, then go all out man!



Thanks Greg, did you try the code I post to observe the behavior? I'm looking for anyone who has an explanation, because it seems like a bug to me.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're adding a carriage return (\r) and a new line (\n). Of course you're going to get that output.
 
Bob Smitheeeee
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Windows eol is \r\n. It happens with \n only as well. Without adding \r\n the output is:



Edit: corrected output.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic