Write a string containing commas and double quotes to CSV

后端 未结 3 1239
遥遥无期
遥遥无期 2021-01-04 03:58

I\'m trying to produce a Google Shopping feed of 30,000+ items in NetSuite, a CRM system that runs server-side JavaScript that it calls Suitescript 2.0. Essentially, it\'s j

3条回答
  •  长发绾君心
    2021-01-04 04:18

    It turns out that, according to the CSV specs, to include double quotes within a string that is already quoted, you need to use two double quotes (""). I changed:

    itemDesc = itemDesc.replace(/"/g, '\"');
    

    to

    itemDesc = itemDesc.replace(/"/g, '""');
    

    I also removed

    itemDesc = itemDesc.replace(/,/g, '\,');
    itemDesc = itemDesc.replace(/'/g, '\'');
    

    Since the column in the CSV is being quoted already. These are unnecessary.

提交回复
热议问题