刪除空格我有多餘的空格的字符串:在CSV文件
First,Last,Email ,Mobile Phone ,Company,Title ,Street,City,State,Zip,Country, Birthday,Gender ,Contact Type
我要分析此行,並刪除空格。
我的代碼如下所示:
namespace :db do
task :populate_contacts_csv => :environment do
require 'csv'
csv_text = File.read('file_upload_example.csv')
csv = CSV.parse(csv_text, :headers => true)
csv.each do |row|
puts "First Name: #{row['First']} \nLast Name: #{row['Last']} \nEmail: #{row['Email']}"
end
end
end
這不行。 「電子郵件」的標題不是「電子郵件」,導致代碼找不到值。 –
對!條紋鑰匙,謝謝 –
謝謝,它適合我! – xdsemx