Open the SHIFT_JIS file in Ruby 1.8.7

This is one of those things that seem funny to her, but I'm stuck ...

I need to open a CSV file that is stored in SHIFT_JIS encoding and decode it in Unicode, and also encode in UTF-8. It seems like it's pretty simple in ruby ​​1.9, but I don't feel particularly adventurous in my Rails application, so I need to stick with 1.8.7.

Any help would be appreciated.

+3
source share
1 answer

Found this out right after I posted this thanks to this thread:

Convert UTF8 to ANSI with Ruby

Here is 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}
+3
source

Source: https://habr.com/ru/post/1732124/


All Articles