Joined July 2014
·

erhard karger

regenstauf
·
·

It helps me a lot to read the german postbank csv. The first conversion gives the umlauts, the second (mothod above gives the Euro sign. What I do not know is why I have it to convert twice : Here the code

class BankCsv
def read(file)
f=File.open(file, "r:ISO-8859-1")
a= f.read
a= a.encode('ISO-8859-1', :invalid => :replace, :replace => '').encode('UTF-8')
a= recodewindows1252toutf8(a)
puts a
end

def recode_windows_1252_to_utf8(string)
    string.gsub(/[\u0080-\u009F]/) {|x| x.getbyte(1).chr.
                                    force_encoding('windows-1252').encode('utf-8') }
end

end
BankCsv.new.read("1.csv")

Achievements
1 Karma
0 Total ProTip Views