'cp1252', 별칭 'windows-1252'라고 생각합니다.
Jörg의 답변을 읽은 후 ruby-doc.org의 Encoding 페이지로 돌아가서 언급 한 특정 인코딩에 대한 참조를 찾으려고 시도했습니다. 그 때 Encodings.aliases
메소드가 발견되었습니다.
그래서이 답변 끝 부분에서 방법을 kludged.
그런 다음 나는 단지 IRB 출력이 개 장소를 찾을 수
... IRB의 출력에 있다는 비해 모두 'ANSI'와 UTF-8로보고, ++ 메모장에서 출력에보고하고, utf-8 파일은 'ANSI'로 볼 때 메모장 + +에서와 똑같은 방식으로 왜곡되었지만 그 장소는 cp1252 및 cp1254를위한 곳이었습니다.
cp1252는 명백하게 내 '파일 시스템'인코딩이므로, 그걸로 가고 있습니다.
는 둘 다 1252 및 1254
에서 UTF-8 정규 표현식에 지금까지 파일을 모두 세트로 작동하는 것 노력하고, 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"
그것은 당신의 OS 로케일에 따라 달라집니다. 독일어 또는 영어의 경우 Windows-1252입니다. 메모장 + +는 이것을 따르지 않고 Windows-1252의 별칭으로 사용합니다. 확실히 ISO 인코딩이 아닙니다. http://en.wikipedia.org/wiki/Windows_ANSI_code_page#ANSI_code_page – Esailija
감사합니다. 저는 그것이 cp1252라고 생각합니다. 그렇습니다. –