From: Todd Burch Date: 2007-05-11T02:41:16+09:00 Subject: Re: Trouble using string.tr() Robert Klemme wrote: > > The backslash is wrong there. > Correct. I thought it was. I was grasping for straws. Robert Klemme wrote: > A more robust way to code this would be to use a HashMap - at least to > initially associate ASCII with EBCDIC chars. So, I'd rather to > > CHAR_MAP = { > 0XC1 => ?A, > 0xC2 => ?B, > # ... > } > > Then you can do: > > ebcdic, ascii = [CHAR_MAP.keys, CHAR_MAP.values].map do |set| > set.inject("") {|st, ch| st << ch} > end > Good suggestion. I haven't used HASHes at all. However (and maybe I don't understand the exampe), but I added this to the very bottom of my script: char_map = { 0XC1 => ?A , 0XC2 => ?B, 0XC3 => ?C, 0XC4 => ?D, 0X6E => ?>, 0XF1 => ?1, 0XF2 => ?2, 0XF3 => ?3, 0XF4 => ?4 } ebcdic, ascii = [char_map.keys, char_map.values].map do |set| set.inject(instring) {|st, ch| st << ch} end puts "ebcdic = #{ebcdic}" ; puts "ascii = #{ascii}" ; puts "instring = #{instring}" ; and it produced some REALLY weird data. What did I do wrong? -- Posted via http://www.ruby-forum.com/.