Rails 纠结的中文乱码问题

goodboyRyan · July 17, 2013 · Last by goodboyRyan replied at July 17, 2013 · 6256 hits

同志们,每次我(mac os)上传歌词都是正常的,但是换成 window 上传就是乱码;刚开始我一个一个的转换,现在受不鸟了,请求帮助?

尝试的解决方案: rails 版本:3.2.13 ruby 版本:1.9.3-p392 1,使用'iconv',不起效; Iconv.iconv("GBK", "UTF-8", xxx) Iconv.iconv("GB2312", "UTF-8", xxx) [04??14.06]??????ʱ????ת?ˣ? 2, 使用 force_encoding("utf-8") 不起效; [04??14.06]??????ʱ????ת?ˣ? 3,直接使用 encoding('utf-8'),不起效;

寻求帮助,先拜谢

歌词?上传到什么上?我记得 ibuick 写过一个 Mac App,解决 windows 下字幕正常,但是在 Mac 下字幕不正常的。

现如今你是 mac 下正常,win 下有问题,解决方案类似啊,还是文件编码问题

对,就是文件编码问题

mac 转码 iconv -f gb2312 -t utf-8 ./public/uploads/lrc/lrc_path/279/1__.txt > public/uploads/lrc/lrc_path/279/11.txt

我怎么用 ruby 转码?请指教

ruby 里面的 iconv, 第二个参数是 -f

class String
   def code_a2b(a,b)
      if RUBY_VERSION > '1.9.2' and defined? Encoding::Converter
        tmp = Encoding::Converter.new(a,b, :universal_newline => true)
        tmp.convert self rescue self
      else
        Iconv.conv("#{b}//IGNORE","#{a}//IGNORE",self)
      end
   end
end

puts "xxx".code_a2b("gb2312","utf8")

#4 楼 @sevk thanks;这个很不错,正在尝试

You need to Sign in before reply, if you don't have an account, please Sign up first.