0

I have a tab delimited text file which has text like the below (for simplicity let's assume its the only column in the file)....

  POWER MAKER FOR SURE.\n\nGREAT THROTTLE RESPONSE

When I read this in, I want it to come through as...

 POWER MAKER FOR SURE
 GREAT THROTTLE RESPONSE

Here is the code where I read this with OpenCSV CSVReader...

csv = new CSVReader(new FileReader(opt.f),'\t' as char, '|' as   char, '\0' as char)
while ((line = csv.readNext()) != null) {
  println("Raw is ${line}")

Notice how I used a different constructor where the escape character has been changed as suggested in this post so that the '\' character is preserved.

But what is being printed is..

 Raw is ["POWER MAKER FOR SURE.\n\nGREAT THROTTLE RESPONSE, BRRRAAAP!"]

Why is not interpreting the newline characters?

Community
  • 1
  • 1
AbuMariam
  • 3,282
  • 13
  • 49
  • 82
  • Where are you getting `CSVReader` from? – Michael Jun 05 '16 at 15:23
  • @Michael, import au.com.bytecode.opencsv.CSVReader – AbuMariam Jun 05 '16 at 15:34
  • So my first thought was in your example string is that literal character slash followed by the letter n or a real new line. If it is the literal slash character then you will need to have some sort of file preprocessor to turn them into new lines as opencsv will not do that for you. – Scott Conway Jun 06 '16 at 22:40

1 Answers1

0

I think is because what is coming from the file is not the actual newline character but just the text '\n'. So I need to do something like

.replace('\\n', '\n')
AbuMariam
  • 3,282
  • 13
  • 49
  • 82