新手问题 编码问题

wwwicbd · July 13, 2016 · Last by shallmentmo replied at July 13, 2016 · 1439 hits

Q1:看起来完全不用考虑编码问题?

>> s = ' 中  文'
=> " 中  文"
>> s[1]
=> "中"
>> s[3]
=> " "
>> s[4]
=> "文"
>> s.encoding
=> #<Encoding:UTF-8>

Q2:要输出'中'这个字符在 utf-8 下的二进制表示需要用哪个方法呢?

谢谢。

我只是好奇地试一下 '中'.bytes.map { |b| '%b' % b }

Binary string literals in Ruby 2.0

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