Stripping whitespace while reading CSV

I’m perplexed over what ought to be a simple CSV question: can you ask
CSV to strip whitespace from individual cells as it reads? The
following works, but is it the approved idiom?

CSV.parse(s).each {|row| row.each {|col| col.strip!}}

  • ff

Fearless F. wrote:

I’m perplexed over what ought to be a simple CSV question: can you ask
CSV to strip whitespace from individual cells as it reads? The
following works, but is it the approved idiom?

CSV.parse(s).each {|row| row.each {|col| col.strip!}}

  • ff

I can’t recall why I stopped using CSV, so I am not the best person to
answer, but it looks okay.
You can use CSV.foreach also.

To see options, on the command line you can do:

ri CSV::new

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs