作者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