-1

I'm trying to convert below message to represent in the text Area which i got from the The JAVA Rest API call (Thirdpaty)and the message is this

String x =   "-----BEGIN PGP MESSAGE-----\nVersion: BCPG v1.58\n\nhIwDmCS94uDDx9kBA/4jkqEOWjbe03C1Dgd2A9eDBdk6cYczsOu6Typm0kjT15uQ\nT+Qc4Koz/yIq4gQpwccxRQ9NGl3Bi1cmPYvwxHIe+4bmqd31Izdkaj1VJCEVqZl2\nrLZvogFOo1oHUmdL2uIdUQJGJgslEOh91wp7CfxGhlxKSg0PvY3gyyWyofUwx9JU\nAUu+NY6YYrfd2l95C7EmMJXUDPysCitl/TGy04DbMuMNAyjZPPfkXqvjcG4A10nk\nPujs6RjnRYyCk+3ZJxvkhsjvGXKIQi7gTgWz7AV8vkBhSM2M\n\u003dRtkb\n-----END PGP MESSAGE-----\n"

When the message displays in the HTML text Area after applying regex patterns

x.replaceAll("(\r\n|\n)", "<br />");
x.replaceAll("(\r\n|\n)", "<br />");

<textarea rows="10" cols="50" id="test" name="test"><%=pKey%> </textarea>

still appearing like this

enter image description here

The Expected Output I'm not getting is this enter image description here

anish
  • 6,884
  • 13
  • 74
  • 140
  • 2
    Are you assigning the value to `x`? See [this thread](http://stackoverflow.com/questions/21436517). Also, is the `\n` a literal string? Then you need `x=x.replace("\\n", "
    ")`. Or `x=x.replaceAll("\\R+", "
    ")`.
    – Wiktor Stribiżew Dec 04 '17 at 08:04
  • You should change your regex like this: `x.replaceAll("\\n)", "
    ");` otherwise the `EOL` character `\n` will be taken into account
    – Allan Dec 04 '17 at 08:14

1 Answers1

1

Use this, x=x.replace("\\n", "<br />"); it will work

PrintWriter pw=res.getWriter();

    pw.println("<textarea name='suggest_list' rows='10' id='word_suggest'>");
    pw.println(x);
    pw.println("</textarea>");
    pw.println("</body></html>");

Output

enter image description here

Vishnu T S
  • 3,476
  • 2
  • 23
  • 39