Archive for February, 2012

09
Feb
12

Ruby CSV with CP932

Ruby is a good language. But little bit unuseful for japanese user include me.

I’ve got often invalid seqence error.

CSV.open(filename, 'r:cp932')

This code is bad.

I found a code in csv.rb below:

    @encoding ||= Encoding.default_internal || Encoding.default_external

This line from /usr/local/ruby-1.9.1/lib/ruby/1.9.1/csv.rb.
I tried use only “Encoding.default_external = ‘cp932′”.

Encoding.default_external = 'cp932'
CSV.open(filename, 'r')

It works.




About

I'm a Japanese programmer.
I have been trying to write technical notes in English on this blog.

Recent Tweet(en)

Recent Tweet(ja)


Follow

Get every new post delivered to your Inbox.

Join 221 other followers