From: ahoward Date: 2003-02-19T03:08:48+09:00 Subject: Re: Reading Text files with extended ASCII characters On Wed, 19 Feb 2003, William Tihen wrote: > Hello, > > I have reviewed the mailing list ruby-talk and I found some interesting > stuff, but I haven't seen the answer to reading (and creating) text > files with extended ASCII characters. > > For example when I try to read a text file with the word: > D�n > seems to work : /tmp > ruby -e "f = File.open 'foo', 'w'; f.puts 'D�n'" /tmp > cat foo D�n /tmp > ruby -e "puts (IO.readlines 'foo')" D�n /tmp > ruby -e "lines = IO.readlines 'foo'; f = File.open 'foo', 'w'; f.puts lines" /tmp > cat foo D�n are you in dos? perhaps trying IO.binmode will help then... when you say > I get: > D\366n > > If I save this and read it in again I get: > D\\366n i assume you mean in irb? if so, this is simply because the display method of strings displays � (and other extended chars) as their octal escaped equivs - the byte value in the file is still the same, which you can see using cat or opening the file from a test editor. -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ahoward@fsl.noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 ====================================