Line/Row separator/delimiter in exported CSV using Ruby CSV -



Line/Row separator/delimiter in exported CSV using Ruby CSV -

is possible alter default line separator newline '\n' or '\r\n' other character, e.g '|' while importing.

i know seems foolish. have multiple records in csv file column address , addresses might contain '\n' in information.

eg corner case x|x|x|x|123 new addr|x|x|x|

normal case x|x|x|x|123|x|x|x|

yes, can alter default separators.

require 'csv' csv.read(csv_file, row_sep: ?|)

but won't help because regardless of separators, csv library not allow \r or \n in unquoted fields.

there's poor man's parser:

file.read(file).split(row_sep).map { |row| row.split(col_sep) }

ruby csv ruby-on-rails-3.2 fastercsv data-import

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -