0

I have searched for way too long, to solve my existing Problem. So, there is a Software, that can only read csv-files with ISO-8859-1 (ISO-Latin-1) encoding. And If tried alost everything I can find on the web, but nothing worked. I don´t want to change the Text, I want to change the encoding.

I´ve tried working with this lib: https://github.com/inexorabletash/text-encoding Library and the PapaParse Library and much more. But they are just converting the Text so there are weird symbols replace ä,ö,ü and other characters.

  • Deducted from the javascript-tag i guess you'd like the converting done by javascript. You can find hints here: https://stackoverflow.com/questions/5396560/how-do-i-convert-special-utf-8-chars-to-their-iso-8859-1-equivalent-using-javasc – Onki Hara Dec 05 '22 at 16:18

2 Answers2

0

The characters in the csv file itself has characters which are not part of the character set which you're encoding into. You might find that the end of lines have a character which does not exist in the character set you want to use. If you open the csv file in a basic text editor or at the dos prompt use Type myFile.csv you will be able to see which charaters there are in a most basic format. Then stip them out and you should have a file that can be converted. Always work on a copy of the original. The easiest way would be to search and replace in a text editor where you replace the unwanted characters with nothing. not even a space. Keep in mind that if the character is part of the csv construct - eg .. a delimiter - then you would want to replace that with the latin equivalent character.

Winston
  • 38
  • 6
  • First: Thank you for the answer. Second: I already did this. CSV, uses ; to write in the next column and /n for the next line. That´s not the problem. – Markus Franzen Dec 06 '22 at 08:43
0

I found it myself, but thank you anyway. In js :

const uint8array = new TextEncoder(
        'windows-1252',
        {NONSTANDARD_allowLegacyEncoding: true}
    ).encode(csv_data);
    const blob = new Blob([uint8array])

(For those, who searched the question: csv_data is an String, containing the values from the read csv-file. Make sure to ad ; behind every value to move to the next column and a /n to move to the next line.) In HTML :

<script>
        window.TextEncoder = window.TextDecoder = null;
    </script>
    <script src="encoding-indexes.js"></script>
    <script src="encoding.js"></script>

And you have to download encoding.js and encoding-indexes.js from https://github.com/inexorabletash/text-encoding