开发者

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


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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜