jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Problem with new line character !!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem with new line character !!!" Watch "Problem with new line character !!!" New topic

Problem with new line character !!!

learning Freak

Joined: Jan 20, 2010
Posts: 5
I have provided a code something like this

string s ="\n";

s.o.p("new line character.");
s.o.p("Not a new line character");

the problem I encountered is it is always displaying "Not a new line character".
where as I m expecting "new Line Character".

What is happening exactly? can anyone explain me briefly ??

Advance thanks.
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199


Welcome to JavaRanch!

First, a bit of business: you may not have read our naming policy on the way in. It requires that you use a full, real (sounding) first and last name for your display name. You can change your display name here. Thanks!

Now, as to your question: if I corrected the capitalization and wrote out "System.out.println()", it should behave exactly as you expect it to. Therefore your real code (which obviously is at least a little different from this) behaves differently because of those differences. If UseRealCode in your post, we could tell you exactly what's up with it -- so let's see!

[Jess in Action][AskingGoodQuestions]
Rob Spoor

Joined: Oct 27, 2005
Posts: 20271

Ernest meant PostRealCode. For one, your code contains two capitalization errors. Secondly, if I fix those two and change the "s.o.p" to full System.out.println statements, it prints "new line character." for me each time I run the code.

How To Ask Questions How To Answer Questions
learning Freak

Joined: Jan 20, 2010
Posts: 5
@ Ernest & Rob .. Thanks for the reply.

In my real code i was using the System.out.println("") ; instead of s.o.p !! Jzt used them for the purpose of post.

The problem with the execution is some times it is getting inserted with a with a character "\r" before my String .

i mean : while debugging it is showing the value in the String var s as "\r\n".

and i m getting the wrong output.

Why the Escape Return character is getting appended ? what is the reason ?

Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46345
Your last post simply makes things even more confusing. If you don't post your real code how on earth are we supposed to understand your problem? You may have problems caused by your operating system; older Macs used "\r" for line end, newer Macs and Unix/Linux use "\n" and DOS/Windows uses "\r\n".

You appear to be ignoring Ernest's earlier warning about names. And it's not "jzt"; please look at this.
I agree. Here's the link: http://aspose.com/file-tools
subject: Problem with new line character !!!
It's not a secret anymore!