简体   繁体   中英

gsub non 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 regular expression: / /

Can anyone tell me how to achieve this?

>> string="foo\xC2bar"
=> "foo\xC2bar"
>> string.force_encoding"ASCII-8BIT"
=> "foo\xC2bar"
>> string.gsub(194.chr, '')
=> "foobar"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM