replace \r\n with \n so can have next line

79 Views Asked by At

i read a string from my csv file like below


BenFeature = fieldSet.readString("ben_feature").replaceAll("\r\n","\n");

the text from my file ben_feature = "Testing \r\n working \r\n"
expecting to be in next like like below
Testing

working

but the out put still have \r\n.

but when i use dummy string

String testing = "Testing \r\n Working \r\n";
testing = testing.replaceAll("\r\n","\n")

this works perfectly.

is the fieldSet.readString is the issue?

1

There are 1 best solutions below

1
geanakuch On

You're saying that the text from my file ben_feature = "Testing \r\n working \r\n" which makes me assume that your text actually contains the \r\n as text. So instead of the control symbols for carriage return and line feed there is a character \ followed by a character r and so on. That will not be picked up by your replace.

If you want to convert these occurences into actual \n you would have to escape the \ like this: \\.

So your code should then read

BenFeature = fieldSet.readString("ben_feature").replaceAll("\\r\\n","\n");