Given a string, I want to replace all double slashes with one slash, and then all instances of \n
with -
. For instance, if I have this:
\\n\\nff
It should be converted to:
\n\nff
And then to:
--ff
I wrote this code:
shippingAddress = shippingAddress.replaceAll("\\\\n", "\n");
For example:
public static void main(String[] args) {
System.out.println("xx");
String x = "enterchar17\\n\\n\\nenterchar17enterchar17\\n\\n\\n\\nenterchar17";
System.out.println(x);
x.replaceAll("\\n","\n");
System.out.println(x);
}
This produces this output:
xx
enterchar17\n\n\nenterchar17enterchar17\n\n\n\nenterchar17
enterchar17\n\n\nenterchar17enterchar17\n\n\n\nenterchar17
so it did not change. I need to escape escape char because somehow spring boot sends 2 slashes. What can i do?
i think JSON does think double as double. It doesn't get it escape?
"line1": "fasfsafasfsa\n\n\nff\n\tasas",
on postman, when i send request like this, \n is converted to "-"
but in postman when i send with double, it cantconvert.
when i inspect to the page where i send request of string, i see this
line1
:
"enterchar17↵↵v↵↵enterchar17↵↵↵enterchar17"
on chromium