This is what I did:
csv = CSV.open(file_name, "r")
I used this for testing:
line = csv.shift while not line.nil? puts line line = csv.shift end
And I came across this:
ArgumentError: invalid byte sequence in UTF-8
I read the answer here and this is what I tried
csv = CSV.open(file_name, "r", encoding: "windows-1251:utf-8")
I encountered the following error:
Encoding::UndefinedConversionError: "\x98" to UTF-8 in conversion from Windows-1251 to UTF-8
Then I came across a Ruby stone - charlock_holmes. I decided that I would try to use it to find the source encoding.
CharlockHolmes::EncodingDetector.detect(File.read(file_name)) => {:type=>:text, :encoding=>"windows-1252", :confidence=>37, :language=>"fr"}
So, I did this:
csv = CSV.open(file_name, "r", encoding: "windows-1252:utf-8")
And still got this:
Encoding::UndefinedConversionError: "\x8F" to UTF-8 in conversion from Windows-1252 to UTF-8
ruby csv
Vighnesh
source share