I try 开发者_运维知识库to output the german setence containing the letter "ü" in escaped form (ascii 252, octal 374, hex 0xfc) using the following code:
pp "Test \374"
pp "Test \374".encode("UTF-8")
But using ruby 1.8.7 I get: "Test \374" "Test \374"
Using ruby 1.9.2 outputs: "Test \xFC" "Test \xFC"
How can I get ruby (1.8.7 + 1.9.x) to output "Test ü"? :)
>> pp "Test \xc3\xbc"
"Test ü"
=> nil
>> s="Test \374" # This has utf-8 encoding but we need it to be "ISO-8859-1"
=> "Test \xFC"
>> s.force_encoding("ISO-8859-1")
=> "Test "
>> s.encode("UTF-8")
=> "Test ü"
>>
精彩评论