Is it possible to change the default field separator from comma to to some other character, e.g '|'
for exporting?
Here's an example using a tab instead.
To a file:
CSV.open("myfile.csv", "w", {:col_sep => "\t"}) do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end
To a string:
csv_string = CSV.generate(:col_sep => "\t") do |csv| csv << ["row", "of", "CSV", "data"] csv << ["another", "row"] # ... end
Here's the current documentation on CSV: http://ruby-doc.org/stdlib/libdoc/csv/rdoc/index.html
The previous CSV library was replaced with FasterCSV in Ruby 1.9.
require "csv" output = CSV.read("test.csv").map do |row| row.to_csv(:col_sep => "|") end puts output
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With