Forum: Ruby on Rails importing text files - file type (UTF-16 for instance)

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jeff P. (Guest)
on 2009-01-16 09:06
I'm using the iFrame and responds_to_parent method to import some text
files (csv files) from various sources.  Some of the files of interest
are in UTF-8 or UTF-16 format.

How can my code determine what the file type is of an imported file?
How can I convert a file from UTF-16 to a 7 or 8 bit file (for now at
least, I'm not required to deal with languages that actually need 16
bits.)  GMail, for instance, exports UTF-16 files, even if the contents
are all English or other 8 bit languages.

So when I import one, I get alternating ascii chars and diamond with a
question mark in the middle chars (I assume that's how my Mac displays
an ascii NULL.

I suppose I could snoop the type from the gathered data by looking for
the alternating null chars, but that seems really cheesy.


This topic is locked and can not be replied to.