0

I have a csv file and I want to get all the values split by comma but the values inside pipe(|) should not be split. Sample row:

145132825311563,400000,D,|2112163531049,1000N1020170421826600001     |,B

I need the output as:

145132825311563
400000
D
|2112163531049,1000N1020170421826600001     |
B

I have tried some approaches given in similar questions but none of them worked for pipe(|).

Vy Do
  • 46,709
  • 59
  • 215
  • 313
r.kothari
  • 43
  • 1
  • 1
  • 4
  • Are you writing your own CSV parser? (why?) Or if not, which CSV parser are you using? In Apache Commons CSV, `CSVFormat.withQuote('|')` should work. – slim Apr 27 '17 at 13:20
  • I am trying with String.split() method. – r.kothari Apr 27 '17 at 13:21
  • OK, don't do that. `split()` isn't good enough once you past the simplest form of CSV. Use a CSV library. – slim Apr 27 '17 at 13:23
  • This answer may help, just change quotes for pipes: http://stackoverflow.com/questions/1757065/java-splitting-a-comma-separated-string-but-ignoring-commas-in-quotes/2120714#2120714 – Steve Smith Apr 27 '17 at 13:32
  • This helped. Thanks much! – r.kothari Apr 28 '17 at 04:59

0 Answers0