From: Paul Battley Date: 2006-07-10T20:09:19+09:00 Subject: Re: Text encodings On 10/07/06, xTRiM wrote: > is there any way, to detect text encoding? > For example, is it in utf8, or in win1251, or something else. You can't detect one-byte-per-character encodings easily (i.e. without statistical analysis) but you can easily tell if something's UTF-8 or not: class String def is_utf8? unpack('U*') return true rescue return false end end "foo".is_utf8? #=> true "foo\303".is_utf8? #=> false Not the most efficient way, necessarily, but probably the easiest. Paul.