Skip to content

Instantly share code, notes, and snippets.

@treeder
Created July 30, 2012 17:29
Show Gist options
  • Select an option

  • Save treeder/3208553 to your computer and use it in GitHub Desktop.

Select an option

Save treeder/3208553 to your computer and use it in GitHub Desktop.
# Install charlock_holmes gem:
# sudo gem install charlock_holmes
# Set filename below and run script.
require 'charlock_holmes'
contents = File.read("documents.txt")
detection = CharlockHolmes::EncodingDetector.detect(contents)
p detection
new_contents = CharlockHolmes::Converter.convert contents, detection[:encoding], 'UTF-8'
File.open("documents_utf8.txt", 'w') {|f| f.write(new_contents) }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment