How do I convert a UCS2 string into UTF8?

前端 未结 3 378
野趣味
野趣味 2021-01-14 14:48

How to convert a string that is in UCS2 (2 bytes per character) into a UTF8 string in Ruby?

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 15:35

    You should look into iconv, which is part of the Ruby standard library. It is designed for this task.

    Specifically,

     Iconv.iconv("utf-8", "utf-16", str).first
    

    should handle the conversion.

提交回复
热议问题