CSV - Unquoted fields do not allow \r or \n (line 2)

后端 未结 8 1357
耶瑟儿~
耶瑟儿~ 2020-12-28 15:38

Trying to parse a CSV file, but still getting the error message Unquoted fields do not allow \\r or \\n (line 2)..

I found here at SO similar topic,

8条回答
  •  滥情空心
    2020-12-28 16:15

    First of all, you should set you column delimiters to ';', since that is not the normal way CSV files are parsed. This worked for me:

    CSV.open('file.csv', :row_sep => :auto, :col_sep => ";") do |csv|
        csv.each { |a,b,c| puts "#{a},#{b},#{c}" } 
    end
    

    From the 1.9.2 CSV documentation:

    Auto-discovery reads ahead in the data looking for the next \r\n, \n, or \r sequence. A sequence will be selected even if it occurs in a quoted field, assuming that you would have the same line endings there.

提交回复
热议问题