• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Carriage return within a text field

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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>?
 
Sheriff
Posts: 22781
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic