On Feb 25, 2008, at 14:25 , Simone Carletti wrote:

> Hi list,
> I run a deep search through this group and other resources online but
> I have been unable to find whether is there a way to guess the charset
> of a string in Ruby 1.8.6.
>
> I need to ensure a string is always UTF-8 encoded but Iconv requires
> the developer to specify both in and out charset.
> On the other side, Kconv provides a #guess() method but doesn't
> support Latin or Western encodings.

The best way is to be aware of the charsets in every data I/O and do  
the necessary housekeeping.

If that's not possible, for example working on arbitrary text files,  
the best approximation that I am aware of in Ruby is the charguess  
library.

-- fxn