How do I use String methods on UTF-8 characters?

前端 未结 4 598
心在旅途
心在旅途 2021-01-15 04:48

How do I use String methods on UTF-8 characters?

For example, I have a string with Cyrillic characters, so when I use string.upcase it doesn\'t work.

4条回答
  •  没有蜡笔的小新
    2021-01-15 05:20

    The rails active_support gem has string extensions that can handle this.

    For example:

    # $ sudo gem install activesupport
    require 'active_support/core_ext/string'
    'Laurent, où sont les tests ?'.mb_chars.upcase.to_s
    # outputs => "LAURENT, OÙ SONT LES TESTS ?"
    

提交回复
热议问题