英文:
How to escape ```\n``` char which is not at the end of the line of the string using java?
问题
String str = "Name, Age, Gender, Description\n"
+ "Test1, 12, M, Hello World\n"
+ "Test2, 21, M, Bye\\\\nWorld";
英文:
I have a csv string. A sample would be ->
String str = "Name, Age, Gender, Description\n"
+ "Test1, 12, M, Hello World\n"
+ "Test2, 21, M, Bye\nWorld";
When I open this in a csv viewer, Bye\nWorld
is creating an issue. How do I escape the \n
char in Bye\nWorld
but not the ones that are at the end of each data using java? The logic should not detect the \n
char at the end of each line, it should only detect the ones that are in the data. An example of the output I want is
Name, Age, Gender, Description
Test1, 12, M, Hello World
Test2, 21, M, Bye\\nWorld
This output will create a correct csv for this data.
专注分享java语言的经验与见解,让所有开发者获益!
评论