transfer GBK into UTF-8 in csv file

Discussion in 'Ruby' started by Pen Ttt, Apr 15, 2010.

  1. Pen Ttt

    Pen Ttt Guest

    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/.
    Pen Ttt, Apr 15, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    4
    Views:
    981
  2. Steven Bethard

    elementtree and gbk encoding

    Steven Bethard, Mar 14, 2006, in forum: Python
    Replies:
    12
    Views:
    1,008
    Steven Bethard
    Mar 15, 2006
  3. higer
    Replies:
    10
    Views:
    882
    higer
    Jun 8, 2009
  4. Pen Ttt
    Replies:
    0
    Views:
    153
    Pen Ttt
    Apr 16, 2010
  5. Stanley Xu
    Replies:
    2
    Views:
    609
    Stanley Xu
    Mar 23, 2011
Loading...

Share This Page