aspose file tools*
The moose likes Java in General and the fly likes Carriage return within a text field Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Carriage return within a text field" Watch "Carriage return within a text field" New topic
Author

Carriage return within a text field

Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Hi,
I have a text field in the database that needs to have carriage returns at various points so that the text is more readable.

I am receiving this in java and sending it out as an email; but when I do so, the \n that I have are printing as such instead of giving me a line break.

I tried to use an escape sequence and had the line breaks as "\\\\n" (for instance the text in data base would be: "Dear Tom, \\\\n How're you?".

Could someone please highlight how to get the line breaks? And what is the escape sequence to be used in this case?

Help would be much appreciated.


Thanks ... Raghu
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38726
    
  23
Is this e-mail sent in html? Have you tried the html line break tag, which I think is <br>?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19692
    
  20

I don't think that's the issue. If that was the only problem, there would be a lack of line breaks. It wouldn't print \n though.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
These are plain-text emails therefore we cannot use any html tags.

I did not follow the third comment? Could you please elaborate?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41793
    
  62
Email clients don't understand the "\n" syntax; that's a Java thing. So you should not be escaping the newline character - use just "\n".


Ping & DNS - my free Android networking tools app
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
Thanks Ulf - but I used \n also ;that did not work ... Should I be using \n within quotes? As in "\n" and have escape characters for "?
Raghu Nathan
Ranch Hand

Joined: Jan 16, 2006
Posts: 44
None of the following have worked so far :

Hello \n World
Hello "\n" World
Hello \"\n\" World
Hello \\\\n World
Hello \\\n World

Any insight would be greatly appreciated!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Carriage return within a text field