How do I do ASCII to EBCDIC translation in Ruby?

后端 未结 2 1970
情歌与酒
情歌与酒 2021-01-25 14:12

I am using Ruby 1.8.7 on Mac OS X.

How do I convert ASCII to EBCDIC encoding, to communicate with legacy system. Would I have to use to jruby?

2条回答
  •  一生所求
    2021-01-25 14:57

    You should use the Ruby iconv library (for Ruby versions before 2.0) or the iconv gem (for Ruby 2+) specifying EBCDIC-US as the codeset:

    irb(main):001:0> require('iconv')
    => true
    irb(main):002:0> x=Iconv.new('EBCDIC-US','ASCII')
    => #
    irb(main):003:0> x.iconv("foo")
    => "\206\226\226"
    

提交回复
热议问题