简体   繁体   English

从CSV生成的输出中删除括号和引号

[英]Remove brackets and quotation marks from CSV generated output

I use CSV to save each line in a text file as a separate object in the database. 我使用CSV将每一行保存在文本文件中,作为数据库中的单独对象。

Each line is saved with added closing brackets and double quotes: 每行保存有添加的右括号和双引号:

["One line of text"]

Is there any option in CSV to exclude those, or else any other nifty way to remove them? CSV中是否有任何选项可将其排除在外,或者通过其他任何巧妙的方式将其删除?

require 'csv'

def self.import_lines_of_text(filename)
  csv_file_path = "db/questions/#{filename}"

  CSV.foreach(csv_file_path) do |row|
    clean_sentence = row.join(",")
    self.create!(content: clean_sentence)
  end
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM