String i/p - Hello\n world!! \nWelcome!!
Hello\n world!! \nWelcome!!
Op -
Hello
World!!
Welcome!!
If \n occurs word will be printed on the next line.
There is no need for a regular expression when wanting to replace one exact thing with one other exact thing, of course.
String in = "Hello\\nworld!!\\nWelcome!!";
String out = in.replace("\\n", "\n");
System.out.println(out);
> Hello
> World!!
> Welcome!!
If you want blank lines in between, replace with "\n\n"
instead.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.