Ruby 1.9: Regular Expressions with unknown input encoding

后端 未结 2 746
一个人的身影
一个人的身影 2020-12-10 12:44

Is there an accepted way to deal with regular expressions in Ruby 1.9 for which the encoding of the input is unknown? Let\'s say my input happens to be UTF-16 encoded:

2条回答
  •  一个人的身影
    2020-12-10 13:20

    Follow the advice of this page: http://gnuu.org/2009/02/02/ruby-19-common-problems-pt-1-encoding/ and add

    # encoding: utf-8
    

    to the top of your rb file.

提交回复
热议问题