LoginSignup
2
0

More than 5 years have passed since last update.

Rubyでutf8のCSVをsjisに変換するワンライナー

Posted at

単純にsjisに変換しようとすると、特殊な文字が入っていた場合にエラーでコケる。ので、encodeメソッドの引数にそれらを無視するオプションを付けておく。
これだけあればパッと変換できるので備忘録代わりに。

File.open(output_csv_path_sjis, 'w') { |f| f.puts File.read(input_csv_path_utf8).encode('Shift_JIS', invalid: :replace, undef: :replace) }
2
0
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0