作者godfat (godfat 真常)
看板Ruby
標題[Ruby] ruby 1.9 utf-8 string support
時間Wed Dec 5 23:11:50 2007
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
1F:推 KCda260:+ 12/18 02:48