I want to take input from user as String
and replace the newline character \n
with ,
I tried :
String test ="s1\ns2\ns3\ns4";
System.out.println(test.replaceAll("\n",","));
Output was s1,s2,s3,s4
But when I try the same code by getting input from UI it's not working.
When I debug it the string test(which I hardcoded) is treated as,
s1
s2
s3
s4
but the string from UI is "s1\ns2\ns3\ns4
".
Please suggest what is wrong.
System.out.println(test.replaceAll("\n",",").replaceAll("\r\n",","));
– Curiel\n
in the string. You may need to interpret escape sequences yourself – Millur