• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Carriage return within a text field

 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50277
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this e-mail sent in html? Have you tried the html line break tag, which I think is <br>?
 
Rob Spoor
Sheriff
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Raghu Nathan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic