How to remove the extra double quote?

后端 未结 5 1930
再見小時候
再見小時候 2021-01-26 02:37

In a malformed .csv file, there is a row of data with extra double quotes, e.g. the last line:

Name,Comment
\"Peter\",\"Nice singer\"
\"Paul\",\"Love \"folk\" so         


        
5条回答
  •  孤街浪徒
    2021-01-26 03:26

    If you're not on Ruby 1.9, or just get tired of regexes sometimes, split the string on ,, strip the first/last quotes, replace remaining "s with _s, re-quote, and join with ,.

    (We don't always have to worry about efficiency!)

提交回复
热议问题