From: Horacio Sanson Date: 2005-11-05T00:07:41+09:00 Subject: Re: double byte string numbers to_int?? I made some testing and so far no luck getting encoded strings to convert to Numeric values. s = "17" => "\357\274\221\357\274\227" puts s => 17 s.to_i =>0 I also tried converting the string with Iconv with no results (Illegal Sequence errors). Playing a little more I got this little method to convert the utf8 encoded string to Fixnum class String def w_to_i digits = self.size/3 res = "" 0.upto(digits-1) { |d| res = res + (self[(d*3)+2] - 144).to_s } res.to_i end end # Example usage s = "0" => "\357\274\220" s.w_to_i => 0 s = "1" => "\357\274\221" s.w_to_i => 1 s = "51" => "\357\274\225\357\274\221" s.w_to_i => 51 s.w_to_i.class => Fixnum This little hack works so far but only for my specific application. Any tips on making this better are appreciated. Also if there exist any easier way (and I believe there must be) I will appreciate any directions. regards, Horacio Friday 04 November 2005 19:54、Christophe Grandsire さんは書きました: > Selon Christophe Grandsire : > > 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 :) . > > I checked around, and my guess is that your original string contains > "fullwidth ASCII variants". For digits, that's U+FF10 to U+FF19. In UTF-8, > those are translated into three-byte characters. So your so-called "double > byte strings" are really six bytes long, and are not treated as containings = "17" => "\357\274\221\357\274\227" > numbers by to_i. -- > Christophe Grandsire. > > http://rainbow.conlang.free.fr > > It takes a straight mind to create a twisted conlang.