Skip to content

Instantly share code, notes, and snippets.

@r38y
Created December 9, 2008 22:15
Show Gist options
  • Save r38y/34120 to your computer and use it in GitHub Desktop.
Save r38y/34120 to your computer and use it in GitHub Desktop.
require 'iconv'
class String
def to_ascii
to_ascii_string = self
begin
result = Iconv.new("CP1250", "UTF-8").iconv(to_ascii_string)
rescue Iconv::IllegalSequence => e
puts e.failed.chars
failed = e.failed.chars.split(//, 2)
to_ascii_string = to_ascii_string.gsub(failed[0], '')
retry
end
result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment