看板 Ruby 關於我們 聯絡資訊
s = '測試' # => "\346\270\254\350\251\246" s.encoding # => <Encoding:ASCII-8BIT> s.force_encoding 'utf-8' # => "測試" s[0] # => "測" s[1] # => "試" s[-1] # => "試" s.size # => 2 s.length # => 2 ('%5s' % s).force_encoding 'utf-8' # => " 測試" ('%-3s' % s).force_encoding 'utf-8' # => "測試 " 所以大概是預設 ascii-8bit, 有 utf-8 string 需求才手動強制轉為 utf-8 string 吧, 想必是效能考量... refer the benchmark: http://groups.google.com/group/comp.lang.ruby/msg/4373ec7ef2403c65 -- Hear me exalted spirits. Hear me, be you gods or devils, ye who hold dominion here: I am a wizard without a home. I am a wonderer seeking refuge. Sacrifice -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.132.58.12
KCda260:+ 12/18 02:48