开发者

How to remove the ' quote from string?

I am trying to upload some data from my csv to the database using fastercsv. here is how my csv looks like:

'name';'number';'sub_category_id';'category_id';'quantity';'sku';'description';'cost_price';'selling_price'
'Uploaded Item Number 1';45;'KRT';'WN';56;'WNKRT0045';'Some Description';4566;6788
'Upload开发者_运维百科ed Item Number 2';56;'PNT';'MN';34;'MNPNT0056';'Some Description';5677;7655

I am getting the data the way I wanted but the strings are being formed like this: :name => "'Uploaded Item Number 1'", :sub_category_id => "'KRT'" .. So, when I save this data into items table the field which contain this data looks like this: 'Uploaded Item number 1' in name, 'KRT' in sub_category_id .. instead of simple Uploaded Item Number 1 in name and KRT in sub_category_id. How this single quote (') can be removed from strings, any idea?


Try within the DEFAULT_OPTIONS settings on fastercsv, change :quote_char to '

e.g.

FasterCSV.foreach(path_to_csv, :col_sep => ';', :quote_char => "'") do |row| 
  use row here.. 
end

See:

http://fastercsv.rubyforge.org/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜