[Ruby] ruby 1.9 utf-8 string support

看板Ruby作者 (godfat 真常)時間17年前 (2007/12/05 23:11), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/1
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

12/18 02:48, , 1F
+
12/18 02:48, 1F
文章代碼(AID): #17Lh-v44 (Ruby)
文章代碼(AID): #17Lh-v44 (Ruby)