62.7.1.1. Email „Re: multi-language support in Ruby“ od Nobu Nakady

At Mon, 16 Dec 2002 04:07:42 +0900,
Shannon Fang wrote:
> I used
>
>     text.gsub!(/&#(\d+);/) do $1.to_i.chr end
>
> to process it, and chr reported that 8217 is too large. I don't know if
> it is related to double-byte support? The entire article is in English,
> IE display is "don't" for the ’... although the apostrophe looks
> a little weird...

Integer#chr makes only sinle byte char.  If you want UTF8
string,

    text.gsub!(/&#(\d+);/) {[$1.to_i].pack("U")}

--
Nobu Nakada
Licence Creative Commons
Tento dokument Ruby, jehož autorem je Radek Hnilica, podléhá licenci Creative Commons Uveďte autora-Nevyužívejte dílo komerčně-Zachovejte licenci 3.0 Česká republika .