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
You can use /n, as in
/n
text.gsub!(/\xC2/n, '')
to force the Regexp to operate on bytes.
Are you sure this is what you want, though? Any Unicode character in the range [U+80, U+BF] will have a \xC2 in its UTF-8 encoded form.
\xC2