Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript FileReader readAsText function not understaning utf-8 encoding characters like ä and ö

I have tried searching this a lot and nothing helped me. I have an import from csv feature and javascript code reads the csv content line by line. The characters ä,ö etc are just not recognized. FileReader readAsText has default encoding utf-8 but in this case it is not for some reason working. Here is my code.

            reader = new FileReader()
            reader.onload = (e) =>
              result = e.target.result
              console.log result
              # file content
              fileContent = result.split("\r")

            reader.readAsText(e.target.files.item(0))

I have tried defining encoding like below and whatever I put there couldn't help me.

encoding = "UTF-8"
reader.readAsText(e.target.files.item(0), encoding)
like image 212
underScorePassionFruit Avatar asked May 25 '15 17:05

underScorePassionFruit


1 Answers

I got this to work by using ISO Latin 4 encoding.

reader.readAsText(e.target.files.item(0), 'ISO-8859-4');

That should work for you but remember to use this particular encoding just for some scandinavian characters.

like image 92
Leolian Avatar answered Sep 21 '22 23:09

Leolian