• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with new line character !!!

 
learning Freak
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have provided a code something like this

string s ="\n";

if(s.startswith("\n")){
s.o.p("new line character.");
}else{
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
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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!
 
Rob Spoor
Sheriff
Pie
Posts: 20611
63
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
learning Freak
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ 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
Sheriff
Pie
Posts: 49841
70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic