Gsub is not an ASCII character in Ruby

I am trying to replace a non-ASCII character from a string with the following code:

string.gsub(194.chr,'')

When I do this, I get the following error:

RegexpError: premature end of regex: //

Can someone tell me how to do this?

+3
source share
1 answer
>> string="foo\xC2bar"
=> "foo\xC2bar"
>> string.force_encoding"ASCII-8BIT"
=> "foo\xC2bar"
>> string.gsub(194.chr, '')
=> "foobar"
+4
source

Source: https://habr.com/ru/post/1759463/


All Articles