transfer GBK into UTF-8 in csv file

P

Pen Ttt

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,286
Latest member
ChristieSo

Latest Threads

Top