For example, there is a line:
String str = "text\ntext"; If you withdraw it:
System.out.printIn(str); Here is what I get:
text text How to display a string like this?
text\ntext I am programming languages and not only after the sign \ are special characters. \n is a newline character. Therefore, stdout shows, following this line character, from a new line. In order to get the result that you need, you need to escape the \ character. You need to replace the source text with text\\ntext , or write System.out.printIn(str.replace('\n','\\n')); before output System.out.printIn(str.replace('\n','\\n')); as @ nick-na wrote
Source: https://ru.stackoverflow.com/questions/805796/
All Articles
replace('\n','\\n')- nick_n_a