repost: system encoding?

E

Emmanuel Touzery

Hello,

I'm reading data from different encodings (web pages), i first
thought about converting all to unicode, but it's not handy right now in
ruby. Then i thought i might as well convert it all to my local encoding
for easy processing in ruby (uppercase, regexps etc) [1]. it's easy to
hardcode my local encoding in the app, but i'd like to make it generic,
to work at my work (windows, cp1250) and at home (linux, iso8859-2).
Hence the question: how can i get a string of my local encoding, on
linux or windows? or how do i tell iconv "convert to my local encoding"?

thank you,

emmanuel
[1] i thought about it late, because i didn't think latin2 has so many
chars from latin1 as it does; many times the conversion would be successful.

Emmanuel said:
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
 
N

nobu.nokada

Hi,

At Thu, 25 Sep 2003 19:41:57 +0900,
Emmanuel said:
I'm reading data from different encodings (web pages), i first
thought about converting all to unicode, but it's not handy right now in
ruby. Then i thought i might as well convert it all to my local encoding
for easy processing in ruby (uppercase, regexps etc) [1]. it's easy to
hardcode my local encoding in the app, but i'd like to make it generic,
to work at my work (windows, cp1250) and at home (linux, iso8859-2).
Hence the question: how can i get a string of my local encoding, on
linux or windows? or how do i tell iconv "convert to my local encoding"?

On many unixes, environment variables LC_CTYPE or LANG would be
used for that purpose. Current linux's iconv accepts both of
iso8859-2 and cp1250, and I expect libiconv for win32 does too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,135
Messages
2,570,783
Members
47,341
Latest member
hanifree

Latest Threads

Top