开发者

gsub non ASCII character in Ruby

开发者 https://www.devze.com 2023-01-11 22:14 出处:网络
I am trying to replace a non ASCII character from a string with the following code: string.gsub(194.chr,\'\')

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 a开发者_如何学JAVAchieve this?


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

精彩评论

暂无评论...
验证码 换一张
取 消