0

I am facing some weird issue.I am fetching a email template from database "Hi \n How are you? \n story continues". I am assigning this to string in my java application and sending email. The final output should be

Hi
How are you?
story continues

But my result is like this

Hi \n How are you? \n story continue

Instead of getting from db, if I hard code in the string I am getting in right way.

What might be causing \n to be ineffective?

Is there a way can I make \n effective in java layer?

gregwhitaker
  • 13,124
  • 7
  • 69
  • 78
jammy
  • 39
  • 2

2 Answers2

2

Try this

    String str = //value read from DB
    str = str.replaceAll("\\\\n", "\n");
Mangoose
  • 922
  • 1
  • 9
  • 17
0

You have to use StringEscapeUtils. The method that you need is unescapeJava().

It is inside Apache Commons Lang.

Vitaly Olegovitch
  • 3,509
  • 6
  • 33
  • 49