0

I have a script that calls an api and returns a text that I save in a csv. The api sometimes returns a text containing ";". This ";" is the delimiter of the csv so it generates new columns in the file. How can I do to "escape" the semicolon and not generate new columns when the text has ";"?

Thanks!

Jonatan
  • 45
  • 5
  • 1
    You could replace ";" with "$semi_colon$" in your text before export and then replace "$semi_colon$" with ";" after import. – gchapuis May 06 '22 at 08:43
  • 1
    I have worked a lot with CSV, and there isn't really any good "covers all" method. Analyze your output and choose a delimiter that you know fairly certainly is not in the text. It can be an accented character, a `§` etc. Fixed-width columns (width is determined by longest column entry) is another way to cover every ascii character. Or go by tab-delimited if you don't need tabs in your output. Escaping `;` is a wormhole that leads to escaping hell. You could end up with `\\\\\\\\;` type results. – MyICQ May 06 '22 at 09:32

0 Answers0