Ar Ik wrote in post #1031208: > C. Zona wrote in post #1031196: >> Your first argument to gsub appears to be ASCII 197. > > Yes, You're correct, but still I do not know how to fix my code...As the > source text contains chars not among 65..90 and 97..122, how I can > remove or replace them? Strings in ruby 1.9 are complicated beasts. I had a go at understanding them: https://github.com/candlerb/string19/blob/master/string19.rb So it really depends on what you're trying to do. If you want to manipulate this file as a series of bytes, and match particular bytes, then open it in binary mode ('rb'), and pass only binary strings to gsub. temp.gsub!("xxx".force_encoding("BINARY"), "") The trouble with opening the file as UTF-8, and doing regexp matches with UTF-8 characters, is that your program will crash when fed invalid UTF-8 data. So it is not good for "data cleaning" exercises. But strangely, ruby 1.9 is quite happy to deal with invalid strings in some contexts. For example, if you do temp.size.times do |i| puts temp[i] end then it will work even if the i'th character is invalid. Go figure. -- Posted via http://www.ruby-forum.com/.