From: Dave Bass Date: 2008-05-31T02:08:30+09:00 Subject: Re: how to generate ascii code? Heesob Park wrote: > irb(main):001:0> require 'cgi' > => true > irb(main):002:0> CGI.unescapeHTML("WELCOME") > => "WELCOME" > irb(main):003:0> CGI.unescapeHTML("WEÿCOME") > => "WE\377COME" Actually CGI.escape and CGI.unescape are such short methods that you can copy and paste them from the Ruby source code rather than requiring the whole CGI kit and caboodle. At least, that's what I do. ;-) def URLencode(string) string.gsub(/([^ a-zA-Z0-9_.-]+)/n) do '%' + $1.unpack('H2' * $1.size).join('%').upcase end.tr(' ', '+') end def URLdecode(string) string.tr('+', ' ').gsub(/((?:%[0-9a-fA-F]{2})+)/n) do [$1.delete('%')].pack('H*') end end -- Posted via http://www.ruby-forum.com/.