How to remove all non - ASCII characters from a string in Ruby

后端 未结 3 955
小蘑菇
小蘑菇 2021-02-01 20:38

I seems to be a very simple and much needed method. I need to remove all non ASCII characters from a string. e.g © etc. See the following example.

#coding: utf-         


        
3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-01 21:20

    Strip out the characters using regex. This example is in C# but the regex should be the same: How can you strip non-ASCII characters from a string? (in C#)

    Translating it into ruby using gsub should not be difficult.

提交回复
热议问题