From: Christophe Grandsire Date: 2005-11-04T19:33:49+09:00 Subject: Re: double byte string numbers to_int?? Selon Horacio Sanson : > > I have some date strings in japanese (utf-8 encoding) like: > > 平成17年10月17日 > > using a regular expresion I can extract the year, month and day in separate > variables but the I cannot convert them to Integer so I can create a Date > object with the values, here is my script: > > > date_string = "平成17年10月17日" > > date_string =~ /平成(\s*\S+\s*)年(\s*\S+\s*)月(\s*\S+\s*)日/ > > y, m, d = $1, $2, $3 > > puts y +", " + m +", "+ d =>17, 10, 17 > > > So I got the numbers in y, m, and d vars but then converting them to Integers > gives me 0 as result > > y.to_i => 0 > m.to_i =>0 > d.to_i =>0 > I may be wrong, but seeing your post without UTF-8 on, I see that the y, m and d strings you get indeed contain the numbers, but as UTF-8 characters which are *not* at the same position as the normal ASCII characters for numbers. I guess that's what confuses to_i. Your strings contain characters that *look* like numbers to us, but are not treated as such by to_i. I'm afraid even the parsing capabilities of Date won't solve the problem. It will probably expect digits that are in their ASCII positions rather than Unicode characters that happen to look like numbers to us :) . -- Christophe Grandsire. http://rainbow.conlang.free.fr It takes a straight mind to create a twisted conlang.