Victor Victor - 2 months ago 11x
Ruby Question

Convert non-ascii punctuation to ascii

I have the following string:

Your résumé’s a non–encyclopædia

Note the , é and æ are non-ascii. I want to leave é and æ intact, but replace the ’ with ascii quote: '.

How can I make such conversion in Ruby (not Rails)? My database is UTF8 and I still wanna store the accented characters, including kanjis, Chinese, etc., but just wanna replace the punctuation.


Found this gem that works exactly what I wanted -

Just do .punctuate!:

irb(main):001:0> require 'punctuate'
=> true
irb(main):002:0> "Your résumé’s a non–encyclopædia".punctuate!
=> "Your résumé's a non-encyclopædia"