2012-03-08 58 views

回答

5

試着這麼做:

1.9.2p290> "foo bar".bytes.to_a # the space is a nonbreaking-space 
=> [102, 111, 111, 194, 160, 98, 97, 114] 

,或者對於字符的十六進制代碼是你的事:

1.9.2p290> "foo bar".chars.map { |c| c.unpack "H*" } # same nonbreaking-space 
=> [["66"], ["6f"], ["6f"], ["c2a0"], ["62"], ["61"], ["72"]] 
+0

這工作(1.9.3),而正是這個問題的好。我沒有意識到有一個像html之外的東西,並且#split贊同它。 – Dogweather 2012-03-08 12:53:13

+1

*每個* HTML實體只是一些Unicode字符的ASCII表示,沒有隻存在於HTML中的「魔術」字符 – Gareth 2012-03-08 13:43:51

相關問題