File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes escape character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "escape character" Watch "escape character" New topic

escape character

Arun Boraiah
Ranch Hand

Joined: Nov 28, 2001
Posts: 233
I am facing a problem where escape character getting printed.
String str = "first \n second";
expected output is
Assume that this string "str" is build by some other part of the program and on printing output i am getting is
first \n second
Please can anyone tell where i am going wrong.
Thanks in advance.

Sharing is learning
Philip Shanks
Ranch Hand

Joined: Oct 15, 2002
Posts: 189
It's just a hunch, but I would double check that the program that creates the string isn't actually creating it as "\\n". In that case the backslash character itself is being escaped to give a literal backslash.

Philip Shanks, SCJP - Castro Valley, CA
My boss never outsources or has lay-offs, and He's always hiring. I work for Jesus! Prepare your resume!
Biju Philip

Joined: Nov 03, 2001
Posts: 7
Note sure if it's what you want, but here's the platform-independent way to do it:

[ November 20, 2002: Message edited by: Biju Philip ]
I agree. Here's the link:
subject: escape character
It's not a secret anymore!