如何使用FasterCSV导入一个名为“Ciarán”的行? [英] How do I import using FasterCSV a row with a name like "Ciarán"?

查看:148
本文介绍了如何使用FasterCSV导入一个名为“Ciarán”的行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想加载我的数据迁移成员数据库。相当多的名字有特殊字符,如Ciarán。我设置了一个这样的简单示例:

I am trying to load in my data migration a member database. Quite a few of the names have special characters such as "Ciarán". I've set up a simple example like this:

require 'rubygems'
require 'fastercsv'

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

p>

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)

用这个名字。

我一直在搜索字符编码和UTF-8,但还没有找到解决方案。我想保留特殊字符,但不想编辑每个失败的成员名称。

I have been googling character encoding and UTF-8, but have not yet found a solution. I'd like to keep the special characters but would rather not have to edit each member name that fails.

非常感谢,
Brett

Many thanks, Brett

推荐答案

我在其他地方看过,这可以通过设置KCODE来修复。例如:

I've read elsewhere that this can be fixed by setting KCODE. For example:

$KCODE = "U"

粘贴在顶部。

James Edward Gray还表示他在FasterCSV中添加了编码支持, 。

James Edward Gray has also said he's added encoding support to FasterCSV but it's in trunk only.

这篇关于如何使用FasterCSV导入一个名为“Ciarán”的行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆