Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ドキュメントを読みましたが、個々のセルをターゲットにして、セルのコンテンツに文字列を事前または追加する方法がまだわかりません。それが重要な場合、ファイルはかなり大きくなります(90MB)。
CSV:
2.22,3.33,4.44,5.55 6.66,7.77,8.88,9.99
この出力が必要です:
%text2.22%,%text3.33%,%text4.44%,%text5.55% %text6.66%,%text7.77%,%text8.88%,%text9.99%
必ず使用する必要がありfastercsvますか? あなたの入力があなたが示すのと同じくらい単純であれば、以下で十分です:
fastercsv
pre_text = '%text' post_text = '%' File.open('outfile.csv', 'w') {|of| File.readlines('input_file.csv').each {|line| of.puts line.strip.split(',').map{|x| pre_text + x + post_text}.join(',') } }