I'm totally new to Scala, and am trying to parse a CSV file that has carriage return/new line/and other special characters like comma in some of the cells (i.e. within double quotations), for example:
"A","B","C\n,FF\n","D"\n
"Q","W","E","R\n\n"\n
"1","2\n","2","2,2\n"\n
I want to load this into a list of lists type in Scala, like the following:
List(List("A","B","C,FF","D"),List("Q","W","E","R"),List("1","2","2","2,2"))
Any suggestions how it can be done?
I have found some solutions for the same problem in other languages. For example this is a great one in Python, which I understand well: Handling extra newlines (carriage returns) in csv files parsed with Python?
My try:
val src2 = Source.fromFile("sourceFileName.csv")
val it =src2.getLines()
val data = for (i<-it) yield i.replace("\"","").split(",")
But it looks like all carriage returns are seen as new lines.