We have a simple string:
let str = "\"abc\", \"def\",\"ghi\" , 123.4, 567, \"qwe,rty\""
If we do this:
let parsedCSV = str
.components(separatedBy: .newlines)
.filter { !$0.isEmpty }
.map { $0.components(separatedBy: ",") }
.map { $0.map { $0.trimmingCharacters(in: .whitespaces) } }
print(parsedCSV)
we get this:
[["\"abc\"", "\"def\"", "\"ghi\"", "123.4", "567", "\"qwe", "rty\""]]
Is there a simple solution (using functional programming) not to split the last element \"qwe,rty\", because we know that it's one whole thing?
"and in general it's easier to just go loop by the columns one by one.