09
Apr
10

FasterCSV and UTF-16

FasterCSV under Ruby 1.8 will throw an obscure error if the input is given in UTF-16:

FasterCSV::MalformedCSVError: Unquoted fields do not allow \r or \n (line 1).

The solution is to convert the data to UTF-8:


require 'iconv'
csv = Iconv.conv('utf-8', 'utf-16', csv)

Then, :encoding => 'u', flag for FasterCSV should be enough to process this file with no problems.

Advertisement

0 Responses to “FasterCSV and UTF-16”



  1. Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.