如何使用 FasterCSV 导入名称类似于“Ciarán&"的行? [英] How do I import using FasterCSV a row with a name like "Ciarán"?

查看:61
本文介绍了如何使用 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

我得到以下信息:

/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 hit the row with this name.

我一直在谷歌搜索字符编码和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.

非常感谢,布雷特

推荐答案

我在别处读到过,这可以通过设置 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天全站免登陆