From: David Masover Date: 2011-01-13T07:35:15+09:00 Subject: Re: String.strip with UTF-8 On Wednesday, January 12, 2011 03:28:38 pm Erik E. wrote: > Hi > > I can't strip the leading whitespace (or what at least looks like > whitespace) from a Ruby 1.9.2 string > > > ruby-1.9.2-p0 :002 > d.entity > => " United Arab Emirates" > ruby-1.9.2-p0 :003 > d.entity.strip > => " United Arab Emirates" > ruby-1.9.2-p0 :004 > d.entity.class > => String > ruby-1.9.2-p0 :005 > d.entity.encoding > => # > ruby-1.9.2-p0 :006 > > > It's inside the Rails 3.0.3 console.. Try this: d.entity[0].ord I'm not sure how useful that will be, but you can compare it to that of a space. It _seems_ to be unicode-aware: ruby-1.9.2-p136 :020 > '☃'.ord => 9731 ruby-1.9.2-p136 :021 > _.to_s 16 => "2603" ruby-1.9.2-p136 :022 > "\u2603" => "☃" And for good measure: ruby-1.9.2-p136 :023 > _.ord => 9731 (If you're wondering, that underscore means "The result of the last command I entered into IRB." It's fantastically useful, though it gets annoying when you want to repeat commands using up arrow, etc.) So, if you get something other than: ruby-1.9.2-p136 :024 > ' '.ord => 32 ...then it's not a space. At that point, maybe report a bug, but maybe you'll also be able to work around it with a regex or something.