views:

38

answers:

1

I want to know how to convert these kind of characters to their unicode form, such as the following one:

Delphi_7.0%E6%95%B0%E6%8D%AE%E5%BA%93%E5%BC%80%E5%8F%91%E5%85%A5%E9%97%A8%E4%B8%8E%E8%8C%83%E4%BE%8B%E8%A7%A3%E6%9E%90

The unicode characters of the upper string is:

Delphi_7.0数据库开发入门与范例解析

Anybody knows how to do the conversion using Ruby? Thanks.

+3  A: 

This is an URI-encoded string:

require 'uri'
#=> true
s = 'Delphi_7.0%E6%95%B0%E6%8D%AE%E5%BA%93%E5%BC%80%E5%8F%91%E5%85%A5%E9%97%A8%E4%B8%8E%E8%8C%83%E4%BE%8B%E8%A7%A3%E6%9E%90'
#=> "Delphi_7.0%E6%95%B0%E6%8D%AE%E5%BA%93%E5%BC%80%E5%8F%91%E5%85%A5%E9%97%A8%E4%B8%8E%E8%8C%83%E4%BE%8B%E8%A7%A3%E6%9E%90"
URI.decode s
#=> "Delphi_7.0数据库开发入门与范例解析"
Mladen Jablanović
were you using 1.8 or 1.9 for that output?
rogerdpack
1.9, haven't tried 1.8, but `URI.decode` should behave identically.
Mladen Jablanović