-1

My data is in the below format

1,"Hello,
World"
2,"HI,Hello" 

I need to remove the line breaks Within the double quotes from Java. The data will look like :-

1,"Hello, World"
2,"HI,Hello"
Klitos Kyriacou
  • 10,634
  • 2
  • 38
  • 70
sumeet agrawal
  • 57
  • 1
  • 12
  • Possible duplicate of [How to remove line breaks from a file in Java?](http://stackoverflow.com/questions/2163045/how-to-remove-line-breaks-from-a-file-in-java) – Gurwinder Singh Dec 21 '16 at 11:24
  • 1
    http://stackoverflow.com/a/2163056/2893693 – Jobin Dec 21 '16 at 11:25
  • @GurwinderSingh This is NOT a duplicate of the Q and A suggested in these comments. This specifically asks how to only remove line breaks *within quotes*. This is actually harder than it seems. (For instance, there may be escaped quotes inside a quoted part.) – Klitos Kyriacou Dec 21 '16 at 11:48
  • If your file is in fact a CSV file, then have a look for a CSV reader API for Java. There are several you can download, but I don't know which ones are good. – Klitos Kyriacou Dec 21 '16 at 12:26

1 Answers1

1

You just can use the String method replace(): str.replace("\"[\s\S]*\n[\s\S]*\""", "")

Ihor Dobrovolskyi
  • 1,241
  • 9
  • 19