How do I delete non-UTF8 characters from a ruby string? I have a string that has for example \"xC2\" in it. I want to remove that char from the string so that it becomes a valid
Try Iconv
1.9.3p194 :001 > require 'iconv' # => true 1.9.3p194 :002 > string = "testing\xC2 a non UTF-8 string" # => "testing\xC2 a non UTF-8 string" 1.9.3p194 :003 > ic = Iconv.new('UTF-8//IGNORE', 'UTF-8') # => # 1.9.3p194 :004 > ic.iconv string # => "testing a non UTF-8 string"