How do I split apart a CSV string in Ruby?

后端 未结 6 821
醉话见心
醉话见心 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:19

    EDIT: I failed to read the Ruby tag. The good news is, the guide will explain the theory behind building this, even if the language specifics aren't right. Sorry.

    Here is a fantastic guide to doing this:

    http://knab.ws/blog/index.php?/archives/10-CSV-file-parser-and-writer-in-C-Part-2.html

    and the csv writer is here:

    http://knab.ws/blog/index.php?/archives/3-CSV-file-parser-and-writer-in-C-Part-1.html

    These examples cover the case of having a quoted literal in a csv (which may or may not contain a comma).

提交回复
热议问题