Say I have a CSV file that has | as a delimiter. I know how to read and print the content but I’m not sure how to go about printing Row 7 has an empty field. It would be nice to show which field it is but my concern right now is to show me the row first and I can try to do the second task.
require 'csv'
require 'pp'
CSV.open("exam.txt", 'r',"|") do |row|
pp row
end
You can use something like
row.index(nil)to find thenilfield. Read theEnumerableandArraydocumentation, you’ll probably find something.