[英]Ruby CSV to separate columns with unicode character
I have a CSV file delimited by the thorn character. 我有一个由刺字符分隔的CSV文件。 I can do: 我可以:
CSV.foreach(file_path, { encoding:'ISO8859-1', :col_sep => "þ" }) do |row|
But I want to be safe with parsing my file and separate columns with a unicode version of thorn. 但是我想安全地解析我的文件和使用unicode版本的thorn分开的列。
I think I'm on the right path with trying different options from within the call, like: 我认为我可以在电话中尝试不同的选项,这是正确的方法,例如:
CSV.foreach(file_path, { encoding:'unicode', :col_sep => "U+00DE" }) do |row|
But I can't figure it out... 但我不知道...
How should I be doing this in Ruby? 我应该如何在Ruby中执行此操作?
Thanks 谢谢
This works: 这有效:
CSV.foreach(file_path, { encoding:'ISO-8859-1', :col_sep => "\u00FE" }) do |row|
Thank you @phoet 谢谢@phoet
Worked this out, doing: 解决这个问题,执行以下操作:
Encoding.name_list.each do |encoding|
CSV.foreach(file_path, { encoding:encoding, :col_sep => "\u00FE" }) do |row|
puts row.inspect
break
end
end
Fun 开玩笑
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.