From: Heesob Park Date: 2008-06-02T14:50:17+09:00 Subject: Re: how to generate ascii code? Hi, 2008/6/2 dare ruby : > Heesob Park wrote: >> Hi, >> >> 2008/5/30 dare ruby : >>> the process >>> from buffer and adding each character to temp string. >>> >>> so please help me to solve this issue.. >>> >>> Thanks in advance... >>> >> >> 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" >> >> >> Regards, >> >> Park Heesob > > Dear Park Heesob, > > thanks for your comments on my question. its working fine now but could > you specify what would be the range of decimal and hexa decimal > reference in your case. A link would be very helpful to me. > > even though its working well iam not getting proper result after 255 in > decimal like , Ā its returning nul. so could you specify the range > for the character reference for decimal and hexadecimal in your case. > Take a look at cgi.rb. It is easy to understand. Here is the snippet: def CGI::unescapeHTML(string) string.gsub(/&(amp|quot|gt|lt|\#[0-9]+|\#x[0-9A-Fa-f]+);/n) do match = $1.dup case match when 'amp' then '&' when 'quot' then '"' when 'gt' then '>' when 'lt' then '<' when /\A#0*(\d+)\z/n then if Integer($1) < 256 Integer($1).chr else if Integer($1) < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U) [Integer($1)].pack("U") else "&##{$1};" end end when /\A#x([0-9a-f]+)\z/ni then if $1.hex < 256 $1.hex.chr else if $1.hex < 65536 and ($KCODE[0] == ?u or $KCODE[0] == ?U) [$1.hex].pack("U") else "&#x#{$1};" end end else "&#{match};" end end end I guess you need to set $KCODE = "U" for greater than 255. Regards, Park Heesob