From: Brian Candler Date: 2010-06-04T19:47:58+09:00 Subject: Re: Unexpected length of £ (pound) character? Anthony Stenhouse wrote: > Hi, > > Today I came across an issue with a customer custom report which was out > by 1 char over 40 or so lines. At first thought I had incorrectly > limited the field length, however the problem is only present where > there is a '£' char. > > For example: > "1234".length => 4 > "1234£".length => 6 (Expect 5) > "1234£6".length => 7 (Expect 6) In UTF-8, "£" is two bytes, and ruby 1.8 gives you the number of bytes. If you want to capture (say) the first 6 characters of the string, try this: >> a = "1234£6789" => "1234\302\2436789" >> a =~ /\A(.{6})/u => 0 >> puts $1 1234£6 => nil This may be sufficient for simple wrapping functions. Or look at the Iconv library. > Is this expected functionality in ruby? It does not seem right in my > mind. ruby 1.9 works in characters. It brings with it enormous complexity, pitfalls and inconsistencies. Pick your poison :-) -- Posted via http://www.ruby-forum.com/.