Menu

#42 Support escapes special characters in a string

Outstanding
closed
nobody
None
1
2015-01-23
2013-12-02
Alexsey
No

Dear collegues. Please add support escaped-string for string values of columns.

Now the following text:
Test \"1"
write to file as :
"Test \""1"""
should be a write to file for escaped-string:
"Test \\"1\""

I tried to write your Encoder class, but this did not work as i wanted. I think, need to write special cell processor for string, wich will converts text to escaped-string. But this is requires that the Encoder is not encoded special characters in the text while writing to file.

Prompt, how do it.

Best regard,
Alexsey Konstantinov

Discussion

  • James Bassett

    James Bassett - 2013-12-02

    Hi,

    Super CSV does not use the backslash (\) character to escape quotes - that's not part of the CSV specification (RFC4180). I'd recommend against escaping this way, as it will make your CSV file less portable as other people might not be able to read it.

    You can see how Super CSV encodes CSV here.

    If you really really want to escape with backslashes, I believe opencsv supports this.

     

    Last edit: James Bassett 2013-12-02
  • FractalizeR

    FractalizeR - 2014-02-03

    Well, you are right, escaping is not a part of an RFC.

    But RFC is not really respected nowdays. For example, fgetcsv() function in PHP supports reading non-conformant CSV files with such escaping: http://php.net/fgetcsv

     
  • James Bassett

    James Bassett - 2015-01-23
    • status: open --> closed
     
  • James Bassett

    James Bassett - 2015-01-23
     

Log in to post a comment.

MongoDB Logo MongoDB