I have a string with extra whitespace:
First,Last,Email ,Mobile Phone ,Company,Title ,Street,City,State,Zip,Country, Birthday,Gender ,Contact Type
You can strip your hash first:
strip
csv.each do |unstriped_row| row = {} unstriped_row.each{|k, v| row[k.strip] = v.strip} puts "First Name: #{row['First']} \nLast Name: #{row['Last']} \nEmail: #{row['Email']}" end
Edited to strip hash keys too