我正在生成列名为name
,description
等的动态csv文件。在description
字段中有逗号,所以当我打开csv文件时会打破列。我需要用包含的双引号转换字符串。
例如:
name, description, price
SSD, Solid state drive, 100
keyboard,some description with comma, 20
我需要用双引号转换字符串
name, description, price
"SSD", "Solid state drive", 100
"keyboard" ,"some description with comma", 20
这里是我用来转换csv的代码:
_.each(product, function(obj){
csvContent += obj.name + "," +obj.desc + "," + obj.price + "\n"
}
我觉得手动添加双引号并不好。是否有任何函数可以将双引号添加到字符串?