7

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)
6
  • 1
    Have you saved the csv file as UTF-8? Commented May 25, 2015 at 17:17
  • In mac I only see an option 'Comma Separated Values (.csv) and that's how the csv is saved Commented May 25, 2015 at 17:20
  • Please provide us a raw ASCII sample of the saving with those characters. Or you can check yourself if it is valid UTF-8 encoding or not. Commented May 25, 2015 at 18:40
  • @MikkoOhtamaa if you mean the text, something like this is the output "Ymp�rist�oppi T�m�n puun rungon tyvi muuttuu vanhemmiten tummaksi ja pitkitt�isuurteiseksi, muuten kuori on valkoinen. Lehti on kolmiomainen ja pitk�k�rkinen ja sen laidat ovat kahteen kertaan sahalaitaiset. Vanhan puun oksat riippuvat ja n�ytt�vyytens� takia se on valittu Suomen kansallispuuksi." Commented May 25, 2015 at 18:50
  • 1
    Doesn't look like UTF-8 Commented May 25, 2015 at 19:09

1 Answer 1

11

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.

Sign up to request clarification or add additional context in comments.

1 Comment

In my case the ñ character didn't work out. I used encoding 'ISO-8859-3' and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.