How to get rid of non-ascii characters in ruby

后端 未结 7 1063
遥遥无期
遥遥无期 2020-11-30 18:55

I have a Ruby CGI (not rails) that picks photos and captions from a web form. My users are very keen on using smart quotes and ligatures, they are pasting from other sources

7条回答
  •  心在旅途
    2020-11-30 19:32

    Here's my suggestion using Iconv.

    class String
      def remove_non_ascii
        require 'iconv'
        Iconv.conv('ASCII//IGNORE', 'UTF8', self)
      end
    end
    

提交回复
热议问题