1

I am generating CSV using below format code, It is working fine but if my text has comma its creating another empty column in csv, is there anyway to generate CSV with comma?

var csvText = "Name,type,\n"

for value in array {
    let newLine = "\(value.name), \(value.type)"
    csvText.append(contentsOf: newLine)
}
     
let path = NSURL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("Report.csv")

do {
    try csvText.write(to: path!, atomically: true, encoding: String.Encoding.utf8)
} catch {
    print("\(error)")
}
Dávid Pásztor
  • 51,403
  • 9
  • 85
  • 116
Rama Krish
  • 373
  • 1
  • 13

0 Answers0