Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
turn ruby strings encoding to unicode (utf-8) from any other
Ruby
Branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
bin
lib/string
test
.gitignore
Gemfile
README.md
README.rdoc
Rakefile
string_utf8.gemspec
string_utf8.rdoc

README.md

string_utf8

turn ruby strings encoding to unicode (utf-8) from any other

install

gem install string_utf8

usage

require "string/utf8"

str = read_string_from_somewhere
# =>  "\xD6\xD0\xCE\xC4"

str.utf8!
# => "中文"

p $enc
# => "gb18030"

tech detail

This gem adds a monkey patch to String class, adding a method naming 'utf8!'.

It guesses what encoding the string is using, and force it to use utf-8 encoding.

You can get what former encoding the string is using by checking $enc

Something went wrong with that request. Please try again.