views:

139

answers:

1

This is one of those things that seems like it should be laughably easy but I'm stuck...

I need to open a CSV file that is stored in SHIFT_JIS encoding and decode it to Unicode and also encode in UTF-8. It sounds like this is pretty straightforward in ruby 1.9 but I'm not feeling particularly adventurous on my production Rails app, so I need to stick with 1.8.7.

Any help would be appreciated.

+2  A: 

Figured it out right after I posted this, thanks to this thread:

http://stackoverflow.com/questions/263271/converting-utf8-to-ansi-with-ruby

Here's what I did:

o = File.open(f).read
u = Iconv.iconv("UTF-8","SHIFT_JIS",o).join
File.open(fo,'w'){|e|e.puts u}
Scott