Nodir Nasirov Nodir Nasirov - 1 year ago 102
Ruby Question

Replacing non standard characters in ruby

I have an array of strings:

strings = ["\u2014 some text", "\u00A0 Foo", "Bar"]

What statement should I write in order to get an array that looks like this:

strings = [" some text", " Foo", "Bar"]

I tried following, but no luck:!{|string| string.gsub!(/(Wu2014|Wu00A0)/, '')}

Answer Source

If you want to remove non-ASCII chars, then{| s | s.encode('ASCII', 'binary', invalid: :replace, undef: :replace, replace: '')}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download