How can I import a string with a name like "Ciarán" using FasterCSV?

I am trying to load a member database in my data migration. Several names have special characters such as "Ciarán". I created a simple example:

require 'rubygems'
require 'fastercsv'

FasterCSV.foreach("/Users/developer/Work/madmin/db/data/Members.csv") do |row|
  puts row.inspect
end

      

and I get the following:

/usr/local/lib/ruby/gems/1.8/gems/fastercsv-1.5.0/lib/faster_csv.rb:1616:in `shift': FasterCSV::MalformedCSVError (FasterCSV::MalformedCSVError)

      

when i click a line with that name.

I am using character encoding for google and UTF-8 but haven't found a solution yet. I would like to preserve the special characters, but would not need to edit every member name that fails.

Thanks a lot Brett

+2


source to share


2 answers


I read elsewhere that this can be fixed by installing KCODE. For example:

$KCODE = "U"

      



Paste this at the top.

James Edward Gray also said he added support for FasterCSV encoding, but only in the trunk.
+3


source


It works right off the bat, but if you need to change the encoding, you can pass the FasterCSV encoding option. For example, to say UTF-8, you can do this:

require 'rubygems'
require 'fastercsv'

FasterCSV.foreach("some file.csv", :encoding => 'u') do |row|
  puts row.inspect
end

      



The encoding parameters are listed in the documentation for new

.

+4


source







All Articles