From: ahoward Date: 2003-02-19T13:09:56+09:00 Subject: Re: Reading Text files with extended ASCII characters On Wed, 19 Feb 2003, William H.Tihen wrote: > Thanks for the help Ara, I guess I just didn't understand the file > operations. Now I will look to solve saving ö Ĉ or 0xF6 as an > actual "�" into a text file. > > I can't seem to get unpack to convert "=264" into "�". > > Any ideas how about /tmp > ruby -e '255.times {|n| printf "%c%s", n, (n == 39 ? "\n" : " ")}' ` a b c e o p q r s t u v w x y ( ) * + , - . / 0 1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J K L M N O P Q R S T U V W X Y Z [ \ ] ^ _ ` a b c d e f g h i j k l m n o p q r s t u v w x y z { | } ~ � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � � /tmp > 1;2c (this may hose your terminal but you get the idea) -a ps. running /tmp > ruby -e '255.times {|n| printf "%d : %c\n", n, n}' | less and searching for '�' you'll see that it's 246 : � not 264. hope this helps. > > > On Tue, 2003-02-18 at 19:08, ahoward wrote: > > 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 > > ==================================== > > > > > > -- ==================================== | 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 ====================================