九月
27

问题的出现:

Rails中处理中文时,会作为单字节处理,如:

“中文”.size => 4

“中文”.reverse => “\304\316\320\326″

解决方法:

安装插件 Multibyte for Rails 后,在rails中使用String#chars访问,如:

“中文”.chars.size => 2

“中文”.chars.reverse => “文中”

其它:

由于其性能并未得到测试,请根据你的应用选择使用。

Resource:

http://wiki.rubyonrails.com/rails/pages/HowToUseUn…

https://fngtps.com/svn/multibyte_for_rails/

http://multibyterails.org/documentation/

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • del.icio.us
  • digg

Tags:

1 Response

Leave a Response

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>