Ruby/File Directory/set encoding

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск

Latin-1, transcoded to UTF-8

f = File.open("data.txt", "r")   # Open file data.txt for reading
f.set_encoding("iso-8859-1", "utf-8") # Latin-1, transcoded to UTF-8
f = File.open("data.txt", "r")   # Open file data.txt for reading
f.set_encoding("iso-8859-1:utf-8")    # Same as above



UTF-8 text

f = File.open("data.txt", "r")   # Open file data.txt for reading
f.set_encoding(Encoding::UTF-8)       # UTF-8 text