Ruby ASCII-8BIT 怎么转换为 GBK?

bluexuemei · June 21, 2014 · Last by DouO replied at June 23, 2014 · 4471 hits

ASCII-8BIT 怎么转换为 GBK?

String#encode

ascii-8bit 是伪编码

  • 如果源数据本就是 gbk 编码,那么 force_encoding('gbk')
  • 如果源数据是其他编码,比如 utf-8, 那么 encode('gbk', 'utf-8')

请教下 怎么 把中文 转为 unicode

#2 楼 @lonre 请教下 怎么 把中文 转为 unicode

ASCII 需要转换成 GBK 吗?GBK 的字符编码不是包括了 ASCII 编码吗?

#5 楼 @DouO 请教下 怎么 把中文 转为 unicode

N 年前研究过,是用查表的方式来解决的。

从 GBK 到 Unicode 的中文字符映射

ruby 应该可以直接按 @lonre 的方法来转码吧。

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