2

When opening a CSV file in Ruby with CSV.open, is there a way to set encoding fallback similar to how it's set in String.encode?

Example:

CSV.open('file.csv', encoding: 'windows-1252:utf-8')

I would like to set something like this:

CSV.open('file.csv', encoding: 'windows-1252:utf-8', fallback: {
  "\u0080" => "\x80",
  "\u0081" => "\x81"
})

I couldn't find this in the docs, but maybe it's hidden somewhere.

Fernando
  • 4,459
  • 4
  • 26
  • 39
  • 2
    Not anything I am aware of, but you might `File#read`, then `String#encode` with a fallback and then `CSV#read` this string. – Aleksei Matiushkin Mar 11 '19 at 13:46
  • May be you could find some help with the answer given [here](https://stackoverflow.com/questions/11733076/how-do-i-robustly-parse-malformed-csv/12772298#12772298) – JL M Jun 10 '19 at 20:48

0 Answers0