From: MonkeeSage Date: 2007-12-07T10:09:59+09:00 Subject: Re: UTF-8 and printf On Dec 6, 6:54 pm, Jose wrote: > On 5 dic, 14:58, MonkeeSage wrote: > > > Unfortunately, I think you'll have to use something ugly like this... > > > def pad(n, s) > > (" " * (n - s.unpack("U*").length)) + s > > end > > [...] > > Hey, thank you very much. The trick of unpack to find the string > length is a nice one. And s.unpack("U*").length is only 4 times slower > than s.length, according to my benchmarks. > > Anybody knows this printf "bug" will be solved in ruby 1.9? > > Regards, > --Jose Not really a bug, just that 1.8 doesn't have native unicode support. But, yes, in ruby 1.9 you have a native utf-8 type, so with default utf-8 encoding, printf Just Works (you can also force utf-8 encoding with String#force_encoding if you're using a different native encoding, and printf does the right thing). :) Regards, Jordan