I'm using Ruby 2.4 with Rails 5. I have the following String
2.4.0 :005 > tr = doc.search("//td").first.text
=> "\r\n \xA0PLACE \r\n "
the String is UTF-8 encoded, although this is just an example. I'm not guaranteed that all data will have UTF-8 encoding.
2.4.0 :007 > tr = doc.search("//td").first.text.encoding
=> #<Encoding:UTF-8>
but when I apply the "strip" method to it, the call dies
2.4.0 :006 > tr = doc.search("//td").first.text.strip
ArgumentError: invalid byte sequence in UTF-8
This is just an example, but how can I override the strip method so it doesn't die when it encounters a character it doesn't like? I don't want to change the string in question. I'm happy to write my own "strip" method, but I want to be able to keep the above exactly as I have it and just not have the error thrown.