Multi-language support in Ruby

Hi,

I encountered a problem. I think it is related to UNICODE support,
however, since the text I’m processing is in English, so… :-S

The string I’m processing is:

“With only 13 shopping days to go until Christmas don’t forget”

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…

How can I let ruby to convert a number larger than 255 in chr?

Thanks!
Shannon

Hi,

···

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 single byte char. If you want UTF8
string,

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


Nobu Nakada