Write a string containing commas and double quotes to CSV

后端 未结 3 1247
遥遥无期
遥遥无期 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:41

    In my case, I didn't want to quote strings that did not need quoting. So I test the string for nasty characters before quoting it.

    function escapeCSV (term) {
      if (term.match && term.match(/,|"/))  {
        return `"${term.replace('"','""')}"`
      } else {
        return term
      }
    }
    

提交回复
热议问题