[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[newbie] specifying file encoding

yvon.thoravallist

9/23/2003 7:14:00 PM


i have a very simple script in ISO-8859-1 :
#!/usr/bin/ruby

w = "émilion"
fo = File.open("capitalize.txt", File::RDWR|File::CREAT,0600)
fo.puts w.capitalize
fo.close

resulting in :
Èmilion E grave instead of Eacute

But the prob arroses because the output file "capitalize.txt" is in
MacOS Roman...

How could we secify the encoding of I/O files ???

In fact, the prob is worth than i thought if i change the encoding of
the file for the script to MacOS Roman

the w.capitalize
is written as :
émilion
that's to say NO capitalisation on accentuated chars ???
--
Yvon
2 Answers

Emmanuel Touzery

9/23/2003 8:39:00 PM

0

On Tuesday 23 of September 2003 21:15, Yvon Thoraval wrote:
> How could we secify the encoding of I/O files ???

a string is considered by ruby as encoded as <insert your locale here>. If you
want to treat strings from other encodings, you can convert encoding using
"iconv" (bundled with ruby 1.8); in your case, you can use iconv to convert
the string to your local encoding (iso-8859-1) and then capitalize will work
fine.

emmanuel

PS: better support for this is planned for ruby 2.0
--
"Droit devant soi, on ne peut pas aller bien loin"
- Le petit prince, Antoine de Saint Exup&#233;ry

Emmanuel Touzery

9/24/2003 7:50:00 AM

0

Emmanuel Touzery wrote:

>a string is considered by ruby as encoded as <insert your locale here>. If you
>want to treat strings from other encodings, you can convert encoding using
>"iconv" (bundled with ruby 1.8); in your case, you can use iconv to convert
>the string to your local encoding (iso-8859-1) and then capitalize will work
>fine.
>
>
which made me wonder: how do I find out what is the current local
encoding for the computer in a portable (unix/windows) way?

emmanuel