How do I split apart a CSV string in Ruby?

后端 未结 6 716
醉话见心
醉话见心 2021-01-06 13:43

I have this line as an example from a CSV file:

2412,21,\"Which of the following is not found in all cells?\",\"Curriculum\",\"Life and Living Processes, Lif         


        
6条回答
  •  不知归路
    2021-01-06 14:15

    This is not a suitable task for regular expressions. You need a CSV parser, and Ruby has one built in:

    http://ruby-doc.org/stdlib/libdoc/csv/rdoc/classes/CSV.html

    And an arguably superior 3rd part library:

    http://fastercsv.rubyforge.org/

提交回复
热议问题