Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > transfer GBK into UTF-8 in csv file

Reply
Thread Tools

transfer GBK into UTF-8 in csv file

 
 
Pen Ttt
Guest
Posts: n/a
 
      04-15-2010
here is my programm
programm1:
require 'csv'
require 'iconv'
CSV.open('/home/pt/test/shbaseback.csv', 'w') do |wrow|
CSV.open('/home/pt/test/shbase.csv', 'r') do |row|
wrow << Iconv.iconv('UTF-8','GBK',row)
end
end

wrong message:
/usr/local/ruby/lib/ruby/1.9.1/csv.rb:1988:in `=~': invalid byte
sequence in UTF-8 (ArgumentError)

programm2:
require 'csv'
require 'iconv'
CSV.open('/home/pt/test/shbaseback.csv', 'w') do |wrow|
CSV.open('/home/pt/test/shbase.csv', 'r') do |row|
wrow << Iconv.iconv('UTF-8','GBK',row.to_s)
end
end
wrong message:
/usr/local/ruby/lib/ruby/1.9.1/csv.rb:1988:in `=~': invalid byte
sequence in UTF-8 (ArgumentError)

i just want to change the csvfile's (/home/pt/test/shbase.csv) code GBK
into UTF-8(/home/pt/test/shbaseback.csv),how can i do?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cp936 uses gbk codec,doesn't decode `\x80` as U+20AC EURO SIGN John Machin Python 1 10-11-2010 08:54 AM
how to use csv to open file in gbk code Pen Ttt Ruby 0 04-16-2010 03:20 AM
how to transfer my utf8 code saved in a file to gbk code higer Python 10 06-08-2009 06:15 AM
elementtree and gbk encoding Steven Bethard Python 12 03-15-2006 09:05 PM
Source Encoding GBK/GB2312 steven@lczmsoft.com Python 4 02-26-2005 06:03 AM



Advertisments