This might work for you.
def mySplit(str: String): List[String] = {
var elems = List[String]()
// break down by quotes first
val quotes = str.split("\"")
for(i <- 0 to quotes.length - 1) {
if(i % 2 == 0) {
// break down by commas second
val subelems = quotes(i).split(",")
for(j <- 0 to subelems.length - 1) {
if(!subelems(j).isEmpty)
elems = elems :+ subelems(j)
// ignore empty elements
}
} else {
// save "whole strings" and
// don't break into commas
elems = elems :+ quotes(i)
}
}
return elems
}
Use it like so:
// quick test
val str = "1,2018,Abc,2018-04-19,Abc,Abc,Abc,b,n,0,Abc,33,0,Abc,\"Sql, Xyz\",Abc,Abc"
val list = mySplit(str)
Here is the scalafiddle.io