我认为它是'cp1252',别名为'windows-1252'。
阅读Jörg的答案后,我回到ruby-doc.org上的
Encoding页面,尝试找到他提到的特定编码的参考资料,这时我发现了
Encodings.aliases
方法。
所以我在这个答案的末尾编写了这个方法。
然后我在notepad++中查看输出,将其视为'ANSI'和utf-8,并将其与irb中的输出进行比较...
我只能在irb输出中找到两个地方,其中utf-8文件以与在notepad++中将其视为'ANSI'时完全相同的方式损坏,而这些地方是cp1252和cp1254。
cp1252显然是我的'文件系统'编码,所以我选择了它。
我编写了一个脚本来复制所有转换为utf-8的文件,尝试从1252和1254中选择。
utf-8正则表达式目前似乎可以处理两组文件。
现在我必须尝试记住在遇到所有这些编码问题之前我实际上想要实现什么目标。xD
def compare_encodings file1, file2
file1_probs = []
file2_probs = []
txt = File.open('encoding_test_output.txt','w')
Encoding.aliases.sort.each do |k,v|
Encoding.default_external=k
ename = [k.downcase, v.downcase].join " --- "
s = ""
begin
s << "#{File.read(file1)}"
rescue
s << "nope nope nope"
file1_probs << ename
end
s << "\t| #{ename} |\t"
begin
s << "#{File.read(file2)}"
rescue
s << "nope nope nope"
file2_probs << ename
end
Encoding.default_external= 'utf-8'
txt.puts s.center(58)
puts s.center(58)
end
puts
puts "file1, \"#{file1}\" exceptions from trying to convert to:\n\n"
puts file1_probs
puts
puts "file2, \"#{file2}\" exceptions from trying to convert to:\n\n"
puts file2_probs
txt.close
end
compare_encodings "utf-8.txt", "np++'ANSI'.txt"