0

I have a string that holds a value thus -

"01/09/2000","09:00","XX","YYYYYYYY YYYY
","XXXXXXX
XXXXXXX ",""~"31/03/2020","","BB","","",""

In the above there is a CRLF in the middle of the Y value, a CRLF within the X value and another before the " at the end of the X value. I want a all the CRLF to be removed from the string so it returns like this -

"01/09/2000","09:00","XX","YYYYYYYYYYYY","XXXXXXXXXXXXXX",""~"31/03/2020","","BB","","",""

What would be the java expression to remove all these?

njzk2
  • 38,969
  • 7
  • 69
  • 107
ChrisT
  • 1
  • 3
    looks like you need a csv parsing library. why reinventing the wheel? – njzk2 Oct 12 '16 at 13:26
  • Check this link [here](http://stackoverflow.com/questions/1612808/how-to-remove-the-carriage-return-from-string-while-pasting-content-to-excel-fil) – Vall0n Oct 12 '16 at 13:27
  • 1
    This question has already been posted and answered, here's [an answer](http://stackoverflow.com/a/593716/6664878) that applies directly to your case – soohoonigan Oct 12 '16 at 13:29

1 Answers1

0

You can use replaceAll on String:

String input = "A\nB";
input.replaceAll("\n", "");
olsli
  • 831
  • 6
  • 8
  • 1
    There's no reason to use `replaceAll` unless you're using regular expressions. There is [`replace`](http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace(java.lang.CharSequence,%20java.lang.CharSequence)) instead. – khelwood Oct 12 '16 at 13:30
  • Ok I agree, but when you look into String.replaceAll and String.replace they do almost the same thing, so it seems it is only cosmetic difference. – olsli Oct 12 '16 at 13:38
  • You're right; there's very little difference, so there is no reason not to use the correct one. – khelwood Oct 12 '16 at 13:48