title: Is there a way in ruby 1.9 to remove invalid byte sequences from strings?
body: <p>Suppose you have a string like <code>"€foo\xA0"</code>, encoded UTF-8, Is there a way to remove invalid byte sequences from this string? ( so you get <code>"€foo"</code> )</p>
  
  <p>In ruby-1.8 you could use <code>Iconv.iconv('UTF-8//IGNORE', 'UTF-8', "€foo\xA0")</code> but that is now deprecated. <code>"€foo\xA0".encode('UTF-8')</code> doesn't do anything, since it is already UTF-8. I tried:</p>
  
  <pre><code>"€foo\xA0".force_encoding('BINARY').encode('UTF-8', :undef =&gt; :replace, :replace =&gt; '')
  </code></pre>
  
  <p>which yields </p>
  
  <p><code>"foo"</code></p>
  
  <p>But that also loses the valid multibyte character €</p>