From: Peter Vandenabeele Date: 2011-01-13T07:50:49+09:00 Subject: Re: String.strip with UTF-8 Erik E. wrote in post #974416: > 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.. > > Erik Hi, I made a fresh install with rvm 1.9.2-p0 and rails 3.0.3 and I cannot reproduce your problem. Maybe you could try to replay what I did and see if you can still reproduce it ? Also, to examine that first character in detail, what is the result when you try this: 009:0> d.entity.bytes.to_a[0..5] => [32, 85, 110, 105, 116, 101] I see a "regular" space (character 32 in decimal notation) as first character. HTH, Peter peterv@ASUS:~/ra/apps/trials$ rvm install 1.9.2-p0 /home/peterv/.rvm/rubies/ruby-1.9.2-p0, this may take a while depending on your cpu(s)... ruby-1.9.2-p0 - #fetching ... Install of ruby-1.9.2-p0 - #complete peterv@ASUS:~/ra/apps/trials$ rvm use 1.9.2-p0 Using /home/peterv/.rvm/gems/ruby-1.9.2-p0 peterv@ASUS:~/ra/apps/trials$ rvm gemset create rails3 'rails3' gemset created (/home/peterv/.rvm/gems/ruby-1.9.2-p0@rails3). peterv@ASUS:~/ra/apps/trials$ rvm gemset use rails3 Now using gemset 'rails3' peterv@ASUS:~/ra/apps/trials$ gem install rails --no-rdoc --no-ri Successfully installed activesupport-3.0.3 Successfully installed builder-2.1.2 Successfully installed i18n-0.5.0 Successfully installed activemodel-3.0.3 Successfully installed rack-1.2.1 Successfully installed rack-test-0.5.7 Successfully installed rack-mount-0.6.13 Successfully installed tzinfo-0.3.23 Successfully installed abstract-1.0.0 Successfully installed erubis-2.6.6 Successfully installed actionpack-3.0.3 Successfully installed arel-2.0.6 Successfully installed activerecord-3.0.3 Successfully installed activeresource-3.0.3 Successfully installed mime-types-1.16 Successfully installed polyglot-0.3.1 Successfully installed treetop-1.4.9 Successfully installed mail-2.2.14 Successfully installed actionmailer-3.0.3 Successfully installed thor-0.14.6 Successfully installed railties-3.0.3 Successfully installed bundler-1.0.7 Successfully installed rails-3.0.3 23 gems installed peterv@ASUS:~/ra/apps/trials$ rails new issue_with_strip create ... create vendor/plugins/.gitkeep peterv@ASUS:~/ra/apps/trials$ cd issue_with_strip/ peterv@ASUS:~/ra/apps/trials/issue_with_strip$ bundle install Fetching source index for http://rubygems.org/ Using rake (0.8.7) ... Using rails (3.0.3) Installing sqlite3-ruby (1.3.2) with native extensions Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed. peterv@ASUS:~/ra/apps/trials/issue_with_strip$ rails g model D entity:string invoke active_record create db/migrate/20110112222955_create_ds.rb create app/models/d.rb invoke test_unit create test/unit/d_test.rb create test/fixtures/ds.yml peterv@ASUS:~/ra/apps/trials/issue_with_strip$ rake db:migrate (in /home/peterv/data/back/rails-apps/apps/trials/issue_with_strip) == CreateDs: migrating ======================================================= -- create_table(:ds) -> 0.0010s == CreateDs: migrated (0.0011s) ============================================== US:~/ra/apps/trials/issue_with_strip$ rails c Loading development environment (Rails 3.0.3) 001:0> IRB.prompt_mode=:RVM # this is a local patch => :RVM ruby-1.9.2-p0 :002 > d = D.create :entity => " United Arab Emirates" => # ruby-1.9.2-p0 :003 > d.entity => " United Arab Emirates" ruby-1.9.2-p0 :004 > d.entity.strip => "United Arab Emirates" ruby-1.9.2-p0 :005 > d.entity.class => String ruby-1.9.2-p0 :006 > d.entity.encoding => # ruby-1.9.2-p0 :007 > exit peterv@ASUS:~/ra/apps/trials/issue_with_strip$ rails c Loading development environment (Rails 3.0.3) 001:0> d = D.find :last => # 002:0> d.entity => " United Arab Emirates" 003:0> d.entity.strip => "United Arab Emirates" -- Posted via http://www.ruby-forum.com/.